-1

This is my code for the .putExtra:

String url = "test";
startActivity(new Intent(MainActivity.this, RelationshipRemoved.class)
                    .putExtra("userInfo", urlTwo));

How do I call the value urlTwo in another file?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
user8488959
  • 57
  • 1
  • 6
  • Possible duplicate of [How do I get extra data from intent on Android?](https://stackoverflow.com/questions/4233873/how-do-i-get-extra-data-from-intent-on-android) – Juan Cruz Soler Sep 06 '17 at 19:59
  • Duplicate of https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application?rq=1 – Malik Ahsan Sep 06 '17 at 20:01

1 Answers1

0

You can receive the value in another Activity (not just another file) reading the value from the received bundle, like this:

String userInfo = getIntent().getStringExtra("userInfo");

or

   String userInfo = getIntent().getExtras().getString("userInfo");

Example:

Activity sending an intent:

Intent intent = new Intent(ActivityOne.this, ActivityTwo.class);
intent.putExtra("userInfo", "abcdef123456");
startActivity(intent);

ActivityTwo receive the data stored :

String receivedValue = getIntent().getStringExtra("userInfo");

the variable receivedValue will contain the string value "abcdef123456".

Jorgesys
  • 124,308
  • 23
  • 334
  • 268