I have an app which has a dashboard containing a Google map (SupportMapFragment) and a few counters being automatically updated by attached sensors. They record a bike ride. Let's call this fragment A.
I have a couple other fragments with for example settings, a list with previous rides. Let's call them to fragment B, C, D.
The fragments are being placed inside a FrameLayout inside a DrawerLayout (with a NavigationView) when pressing an item in the navigation view the fragment changes. This works fine, only that when returning to fragment A a new view is created with a clean map (aka not containing a trace line of the currently recorded ride), and empty sensors.
Fragment A always gets created on the creation of the drawer layout activity. Fragments B/C/D get created over this, when onBackPressed or the dashboard item is pressed in the menu those fragments get popped from the back stack and only A remains.
My question is the following: How can I keep the views inside Fragment A active/in memory so the line on the map continues to be drawn while visiting another fragment? And they are still there when I come back to fragment A?
I achieved the same thing when I had a separate activity for the dashboard and using the android:launchMode="singleInstance"
modifier in the manifest.
One of the things I also tried is placing setRetainInstance(true)
inside fragment A.
Thanks in advance.