I suggest introducing EventBus into your application.
To add a dependency, add compile 'de.greenrobot:eventbus:2.4.0' to the list of dependencies.
Then you simply sign your third tab fragment to listen to the events from the first fragment.
Something like this: in fragment B
@Override public void onAttach(Activity activity) { super.onAttach(activity); eventBus.register(this); } @Override public void onDetach() { eventBus.unregister(this); super.onDetach(); } @SuppressWarnings("unused")
NewDataEvent.java
public class NewDataEvent extends EventBase { public NewDataEvent() {} }
And in Fragment A just send the event:
protected EventBus eventBus; .... eventBus = EventBus.getDefault(); .... eventBus.post(new NewDataEvent());
(and to avoid handling the event in the second tab - just pass an additional parameter during the creation of the fragment if it should listen to the event)
source share