I recently started refactoring my Android application by replacing "all" activities with fragments. In the state it is right now, it behaves a lot worse than before...
My problems are in the area of "up navigation", backstack behaviour and general "repainting" of fragments when they are brought to front.
So I have created a logical hierarcy of fragments in my ui and when the user is in the main menu, the "up" button shouldn't be displayed. When the user is in any of the other fragments the up button should take the user back to the main menu.
When I started implementing this, I just put a
activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
In my fragment's onResume method. This works as expected until the main menu is brought to front from the back stack (or the home navigation). Then the onResume() method isn't called.
Wanting to "repaint" the fragment when the user have been somewhere else in the app seems like the kind of thing that a large share of developers want to do. I have read some solutions to this that basically include listening to backstack changes and then calling onResume() for the fragment that is about to come back. This solution feels like a ugly hack that you shouldn't have in a real application. So how do developers of large applications handle this? What is the best practice? Or have I missed some principle saying how to not code myself into this corner at all?
I must say that I think the Android dev page for fragments is almost lying about the lifecycle:
"Managing the lifecycle of a fragment is a lot like managing the lifecycle of an activity"
"Resumed: The fragment is visible in the running activity."
This information implies that onResume() should be called when the fragment goes from invisible to visible.
Also, my solution to providing up navigation is obviously not correct, any tips on how to get proper behaviour?
Thanks for you help!