简体   繁体   中英

Android: always launch start activity when app is destroyed and recreated

Lets say I have two activity, A and B. A - is my splash activity, and it also handles the initialization part. When i launch app, Activity A is started or launched and then it gets navigated to Activity B . Then i press home button , and wait for some time, for app to be destroyed. And i press my app's icon again, and my android (5.0) remebers what activity i stoped using, and launches it (activity B). and App crashes, since initialization was not occured. How to force android to start my activity A in any case?

I had also tried android:clearTaskOnLaunch="true"

I had even tried to finish() activity if it is activity B, but anyway onCreate of fragments are called, and app crashes.

Any help will be appreciated. Thanks in advance

Why don't you call finish(); on your Activity B's onStop() method. It could close your Activity B once the focus is off from the activity and now the app can start from Activity A again on relaunch.

May be this can help you...

Don't rely upon Activity A and B dependence. We do not have any control whether the OS decides to kill any of those. It might be due to battery limits or a need to free up memory.

This can be also checked with 'Dont keep Activities' developer option.

What I suggest doing is adding an if-check logic in Activity B to use the init config or init it, if not possible.

Then, you will be prepared for the case of Android killing your activity (rare case than A -> B flow, but possible).

Hence, Activity logic coupling is a no-go.

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