Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing Action Bar titles when using fragments and the backstack

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?

like image 272
RunLoop Avatar asked Dec 13 '25 17:12

RunLoop


1 Answers

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

like image 81
vipul mittal Avatar answered Dec 15 '25 07:12

vipul mittal