0

I found a lot of informations about the setRetainInstance method, but I'd like to know how to implement this method in a Navigation Drawer Activity?

I basically have:

  • An Activity, that contains...
  • a NavigationDrawerFragment, that contains...
  • a TopLevelMapFragment (showing Google Maps).

My aim is to prevent a reload of the whole maps and its tracks when the user rotates the screen. What is the basic concept of setRetainingInstance in an Navigation Drawer Activity? Do I have to call setRetainingInstance(true) in the NavigationDrawerFragment AND the TopLevelMapFragment?

theRunner
  • 179
  • 1
  • 8

1 Answers1

0

I finally found the solution to my Problem: When I created the Navigation Drawer Activity, I relied on the default Navigation Drawer Activity-template of Android Studio. In this template, the FragmentTransaction-replace method is called each time the user clicks on an item in the Navigation Drawer. Problem: the replace-method destroys all the fragments that are in the specified container. So if you want to keep your fragments alive, don't ever use the replace method. You have to use the methods add, show and hide instead. In addition, I call the setRetainInstance(true)-method in my Google Maps-Fragment, so that the fragment stays alive when the user rotates the screen for example.

theRunner
  • 179
  • 1
  • 8