You could send an event to your activity when the fragment is started :
https://www.inkling.com/read/programming-android-mednieks-1st/chapter-11/visualizing-the-fragment-life
By overriding the onStart method :
@Override
public void onStart() {
super.onStart();
((MyInterface)getActivity()).onFragmentIsVisible( this );
}
Where MyInterfaceis an interface :
public MyInterface {
public void onFragmentVisible( Fragment fragment );
}
and your activity will have to implement it.
This could be more easy with an event bus library like
- RoboGuice's event bus
- Otto
- EventBus