android - What happens when App crashes? -


I am developing an Android app and, as expected, there are situations where my code crashes (bugs, tap pointer, e.t.c. ).

When the app crashes, it automatically restarts, even if I have not written any code to do it (I think this is the default behavior?!) But the problem is, the app The state is opening in the wrong place.

Usually, this happens when the app starts:

  • Initially, the app opens with "Splash Screen". This screen attempts to authenticate the user by using the prevailing tokens in share preferences and loading some basic values ​​from the server and continuing them in some services.
  • Based on the login success, it either goes to the main screen or the login screen.

When the app starts normally, it all works well and the initial sequence is expected to execute but when it restarts as a result of the accident, the value would be splash The population in the screen piece (such as logging in the user or loading the default value from the server) is all invalid, which means that they are never executed.

This leads me to believe that the sequence of events is completely wrong when the app is restarted, meaning that instead of using the correct activity, the manifestation of the manifest as a launcher in the manifest It seems that it is wrong to start things wrong and start with the wrong activity.

So here's the question: Does it determine whether my app will restart itself when I crash and what determines how it should be started? Is there an event that can come to me when the app starts with crash, so that I can override the initialization sequence? Is there any way to force app to start with the launcher activity?

Many thanks in advance,

Due to the crash, when any activity restarted If the process of running foreground activity is over, then the system will remove that activity, if it does not have a valid saved status (usually means it has been stopped and save the system before stopping InstantState The result is given). Once the system has decided whether or not to throw that activity, the activity that is now on top of the stack will start again. If this is one of your activities, either because you have a crashed situation in some way, behind anybody who has crashed, or who has crashed, then the system will resume your process, Can show activity. You try to set clearTaskOnLaunch = "true" for other activities except the main code in the Android Manifest's main activity (launcher activity) declaration and android: finishOnTaskLaunch = "true" And see if it prevents the app from restarting the rest of the state after the accident, in another way it has to be ascertained that to restart your activity, check at the starting point that this activity has all the necessary data Or not. Redirect to the launcher activity if it does not contain all the necessary data. Hope it helps.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -