0

I'm very new to Android development.

I've made some researches to achieve passing data from Fragment A in Activity A to Fragment B in Activity B. Is that possible?

All I could get from the tutorials on the internet is that we have to create an Interface that will be implemented by the parent Activity of two sibling fragments. How to achieve it when the fragments belong to two different activities? I'm stuck.

Thanks

Jaymin
  • 2,879
  • 3
  • 19
  • 35
dodie
  • 1
  • 2

2 Answers2

0

You would achieve it by implementing the said Interface and put the extras into the Intent for the Activity that has the other Fragment.

Pseudo code could look like this

Fragment A - calls interface methods on Activity A and passes data

Activity A - calls startActivity with the extras inside the Intent

Activity B - got started and evaluates the said Intent and passes it to Fragment B

Fragment B - receives the extras from Activity B

Murat Karagöz
  • 35,401
  • 16
  • 78
  • 107
0

you can use Intent to pass data between activity and from sibling fragment call method of activity like ((MainActivity).getActivity).methodSentData(String exampledata) and ((MainActivity).getActivity).methodGetData(); to get data in the fragment.

methodSentData implements intent.putExtra("data",data); to sent data to other activity and methodGetData() implements getintent().GetStringExtras("data");

You can use local broadcast receiver.

asim
  • 310
  • 1
  • 8