I'd suggest to introduce EventBus
in your app.
To add dependency - add compile 'de.greenrobot:eventbus:2.4.0'
into your list of dependencies.
Then, you just subscribe your third tab's fragment to listen to event 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") // invoked by EventBus
public void onEventMainThread(NewDataEvent event) {
// Handle new data
}
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 event in 2nd tab - just pass extra parameter during instantiation of fragment, if it has to listen to the event)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…