I have two activities A and B.
I have a mapview inside a fragment in activity A and on button click ,activity B is launched. The lifecyle goes like this:
onPause() in fragment inside A
onPause() in activity A
onStop() in fragment inside A
onStop() in activity A
When I press the physical back button on the device from activity B, it returns to activity A and the flow goes like this.
onStart() in activity A
onStart() in fragment inside A
onResume() in activity A
onResume() in fragment inside A
Now I have a custom toolbar set as actionbar using setSupportActionBar(mToolbar)
in ActivityB. I have also set getSupportActionBar().setDisplayHomeAsUpEnabled(true);
for back navigation and it displays a left arrow.
The problem is that on click of left arrow,the activity A is getting recreated again.
The lifecycle goes like this:
onDestory() in fragment(in Activity A)
onCreate() in activity A
onCreate() in fragment
onCreateView() in fragment
onStart() in activity A
onStart() in fragment
onResume() in activity A
onResume() in fragment
And because of this, the map in activity A fragment is getting reloaded again.
Any can we prevent the fragment getting destryoed on back navigation?
Thanks in advance