Dinesh Kumar
Dinesh Kumar

Reputation: 488

Send data from Textview in one fragment to another fragment which are in two different activities

How can I use the text in textview in one fragment in mainactivity from another fragment in another activity(activity_main2) .

Upvotes: 1

Views: 62

Answers (2)

Loic P.
Loic P.

Reputation: 711

You can pass extras between activities.

Then, in your MainActivity, add:

Intent intent = new Intent(getBaseContext(), Activity_main2.class);
intent.putExtra("EXTRA_KEY_TEXT", "myText");
startActivity(intent);

And add to your Activity_main2:

String textFromMainActivity = getIntent().getStringExtra("EXTRA_KEY_TEXT");

Hope it helps you!

Upvotes: 1

kalabalik
kalabalik

Reputation: 3832

Basically you will have your FirstFragment communicate with your MainActivity, your MainActivity with your OtherActivity, and your OtherActivity with your SecondFragment. For the specifics see my answer here!

Upvotes: 1

Related Questions