I'm building an Android App using Android Studio. Let's say I have Activity1 and Activity2. Activity2 has 3 fragments (3 tabs). I managed to pass data from Activity1 to Activity2 and then from Activity2 to it's fragments by using a Fragment Adapter.
1) I want to do the opposite: gather data from all 3 fragments and pass it to the activity they are sitting in (Activity2), and then pass the data from Activity2 back to Activity1.
I have implemented an interface that passes data from one fragment to Activity2, but how (and when) can I pass data from all 3 fragments to Activity2? The method I wrote sends an object from a fragment to Activity2. But the method in Activity2 gets only one object... Or perhaps there's a way I can send the data from the fragments to the Activity2 Fragment Adapter? (This can be the best I think...)
2) Is the best way to pass data from Activity2 back to Activity1 is by overriding "onBackPressed" and using startActivityForResult and setResult? (I don't have a button to do that besides the ActionBar "back button").
Thanks!