3

My app has an activity which uses the FragmentManager to push and pop fragments onto the backstack. However, when the backstack has 2 fragments and the last fragment is popped, I do not how to detect this to set the title of the Action Bar appropriately. I was hoping there was some method on a fragment I could override to determine when it becomes visible, but none of those suggested e.g. uservisiblehint, onHiddenChanged, etc. are called. How can I either:

• determine when a fragment becomes visible; OR

• effectively manage action bar titles when using fragments on a backstack?

RunLoop
  • 20,288
  • 21
  • 96
  • 151

1 Answers1

6

You can add a addOnBackStackChangedListener which will get called every time back stack changes. Inside this function you can simply get the topmost fragment and call onResume for it.

For more information you can refer to following link:

Fragments onResume from back stack

Community
  • 1
  • 1
vipul mittal
  • 17,343
  • 3
  • 41
  • 44