Android data transfer from activity to another activity's tablayout fragment

45 views Asked by At

OneActivity -> TabLayout - > FragmentA, FragmentB, FragmentC

TwoActivity -> some clickable widgets

From FragmentA I will go to TwoActivity ang again from TwoActivity to another instance of TwoActivity and again from TwoActivity to another instance of TwoActivity and if some action happens in these TwoActivity I want to have that action value in FragmentC of OneActivity if user navigate to FragmentC.

I tried eventbus but not found solution for it. I want to know the best design pattern for this purpose.

2

There are 2 answers

2
Khalid Taha On

you can use startActivityForResult and override the method onActivityResult in the OneActivity to handle the result returned from TwoActivity and forward the result to FragmentC in your own method. Another way you can use Observers and Observable here

2
Vicky Kumar On

Follow these steps:

1.) call startActivityForResult to navigate to TwoActivity.

2.) Override the onActivityResult(int requestCode, int resultCode, Intent data) into the OneActivity.

3.) and call setResult into TwoActivity while finishing it.

4.) and in onActivityResult proceed to whatever fragment you interested with tabs.