I'm developing an Android app and as expected, there are situations where my code crashes (bugs, null pointers, etc.).
When the app crashes, it restarts itself, even though I haven't written any code to do it (I imagine it's the default behavior?!) but the problem is, the app is opening in an incorrect state.
Here's what generally happens when the app starts up:
- Initially, the app opens with a "splash screen". This screen attempts to authenticate the user using persisted tokens in shared preferences and loading some default values from the server and persisting them in some services.
- Depending on the login success, it either goes to the main screen or the login screen.
When the app starts normally, it all works fine and initialization sequence is executed as expected but when it is restarted as a result of a crash, the values that would've been populated in the splash screen fragment (such as logging in the user or loading the default values from the server) are all invalid, meaning they are never executed.
This leads me to believe that the sequence of events when the app restarts itself are completely wrong, i.e. instead of restarting the app using the correct activity, specified as Launcher in the manifest, it seems to restart things incorrectly and start from the wrong activity.
So here's the question: What determines that my app should restart itself when a crash happens and what determines how it should be started up? Are there any events I could catch when the app starts up from a crash so that I can override the initialization sequence? Is there a way to force the app to always start from the launcher activity?
Many thanks in advance,
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…