简体   繁体   中英

Activity destroyed when launching app

I am working on an application that has Activities A and B. If I navigate from A -> B, background the app then foreground the app Activity B is destroyed and I am brought back to Activity A.

Initially I thought that this was an issue of the Activity B's state not being restored when the app was brought into the foreground but after implemented onSavedInstanceState()/onRestoreSavedInstanceState() I am still seeing this issue.

Placing a breakpoint in the Activity B's onDestroy() shows that the ActivityThread.handleDestroyActivity() is being called immediately when the app is foregrounded without an attempt to restore the activity.

I am currently using android:LaunchMode="singleTask" in the AndroidManifest for ActivityA and android:LaunchMode="standard" for ActivityB. ActivityB is being launched from Fragment on ActivityA.

Does anyone know why Acitivty B does not persist after the app is backgrounded and foregrounded?

I was able to find an explanation for the behavior I was seeing in this post: Android: bug in launchMode="singleTask"? -> activity stack not preserved

Essentially if the activity uses launchMode=singleTask the task will be recreated each time the app is launched and the root activity will be relaunched. This effectively clears any activities sitting on top of Activity A from the taskstack.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM