0

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)

VSB
  • 9,825
  • 16
  • 72
  • 145
  • [check fragment lifecycle callbacks](https://stackoverflow.com/questions/32723055/hooking-into-fragments-lifecycle-like-application-activitylifecyclecallbacks) – sanemars Jun 25 '18 at 09:58
  • @sanemars It is not possible to check this inside fragment instance? I noticed that `onFragmentDetached` is called inside activity callbacks but it is not called inside fragment itself. – VSB Jun 25 '18 at 10:13

0 Answers0