I use a FragmentTransaction
to show my fragment inside my activity and also I add it to backstack like this:
getSupportFragmentManager().beginTransaction()
.addToBackStack(null)
.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left)
.replace(R.id.parentRelativeLayout, myFragment)
.commit();
When back button is pressed I check if myFragment
is on top and if it is the case, I just call super.onBackPressed()
to pop it from back stack and show previous fragment.
I want to know which event/callback on my fragment could help me to detect it is not shown on activity anymore.
I used onPause()
, onDetach()
and ... but they are not triggered (as it is dsecribed https://stackoverflow.com/a/16252923/1080355)