Fragment Backstack after Process Death
Asked Answered
W

0

8

As I observed it seems that the fragment backstack is not retained after process death. So if I kill my app by putting it to background and call am kill <app> it does not recreate the fragment backstack if i take the app to foreground again.

This seems to be the case with both - using Jetpack Navigation Components and using supportfragmantmanager with addToBackStack

After Orientation change everything works as expected. So I don't know whether the backstack is always cleared after process death and cannot be retained or if there have to be some extra steps done to retain the backstack.

Westbound answered 15/4, 2021 at 12:2 Comment(8)
am kill and "process death" (i.e., due to memory, etc.) are very, very different things. What makes you think they are related?Inchworm
@Inchworm Saved instance state survives am kill, whereas it does not survive other common "kill" things that a developer might try (swiping the task off the overview screen, red "stop" buttons in Studio). If there is a better way for a developer to simulate the OOM killer terminating the app's process, I'd love to hear about it! I assume that the Jetpack implementation of fragment stores the backstack details in saved instance state.Beaker
@Beaker as i found out now the Logcat window offers a Terminate Application button that works and keeps the backstack. But it is interesting to see that it only works if I do the following: App to background -> Terminate Application -> App to foreground -> App to background -> Terminate Application -> bring back go foreground. So i have todo the cycle twice to save and restore the backstack.Westbound
Please provide an explicit code sample that demonstrates the problem.Diazine
not any solutions for this?Karrikarrie
@Beaker To really reproduce an app process being killed as the user would experience, you can go to Developer options -> Background process limit and change to "No background processes"Contracted
@ItayFeldman: I have seen a lot of developers burned by that option, so I never recommend it.Beaker
@Beaker Not sure what you mean by burned but I've done some state handling in my VMs not long ago and this was the best way I found to produce the behaviour my users might experience :) It probably fits for some scenarios more than the others.Contracted

© 2022 - 2024 — McMap. All rights reserved.