Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send String from an Activity to a Fragment of another Activity

I have two Activities (A and B) and a Fragment F The Fragment F is contained in the Activity B I'd like to send Strings from Activity A to Fragment F How can do that? Thanks!

like image 915
user1885868 Avatar asked Dec 06 '22 08:12

user1885868


1 Answers

It is Almost same as you would exchange data between activities. you should just use getActivity() in the beginning in order to access in fragments.

check below code:

In Activity A:

Intent intent = new Intent(this,ActivityB.class);
intent.putExtra("data",data); //data is a string variable holding some value.
startActivity(intent); 

In fragment F of Activity B

String data = getActivity().getIntent().getStringExtra("data");
like image 59
SKK Avatar answered Mar 08 '23 23:03

SKK