0

I am programming in android for a Samsung tablet, and I have 2 activities, one of this is a list of football teams, and the other activity is their twitter, but i have a problem to pass the parameter for the first activity to the second one. I want to pass their url like a string, but i cant get it. Thanks!

Itzal
  • 11
  • 1
  • 3

3 Answers3

1

You have to use Intent:

Intent i = new Intent(this, SecondActivity.class);
i.putExtra("extraURL", "http://myUrl.com");
startActivity(i);

Then, to retrieve it in SecondActivity, in the onCreate method do:

Intent receivedIntent = getIntent();
String myUrl = receivedIntent.getStringExtra("extraURL");
manelizzard
  • 1,060
  • 8
  • 19
1

You typically launch the 2nd Activity from the first using an Intent. You can pass data to the 2nd Activity using the same Intent you use to launch it. For example,

Intent i = new Intent(this, SecondActivity.class);
i.putExtra("url", "http://url.you.want.to.pass/");
startActivity(i);

In the 2nd Activity, in the onCreate, you can read the data using:

Intent i = getIntent();
String url = i.getStringExtra("url");
sparkymat
  • 9,938
  • 3
  • 30
  • 48
0

your First Activity on click of button

Intent intent = new Intent(this,ActivityTwo.class );
            intent.setAction(intent.ACTION_SEND);
            intent.putExtra("www.google.com",true);
            startActivity(intent);

Receive it in ActivityTwo:-

 Intent intent = getIntent();
        String msg = intent.getStringExtra("www.google.com");
Monty Sharma
  • 183
  • 2
  • 13