System.exit(0) Causes The Activity Quit Quickly When The App Starts
I met a problem, System.exit(0) cause the Activity quit quickly when the app start: in a project, i see that use System.exit(0) to realize the complete exit of app, and i do that,
Solution 1:
Do not ever use System.exit(0). That goes against the Android coding practices. It's designed to quit the app immediately which is not what you want. If the user presses "Home" or "Back", the Activity will be popped from the stack and all those lifecycle methods will be called. An alternative is to use the finish()
method if you have a reason to leave the app pre-maturely.
Solution 2:
Just to let you know. Force closing an Activity
or an Android App will not continue calling its lifecycle methods specially onDestroy()
. Use finish()
instead
void exit()
{
finish();
}
If you really want to exit your android app, close all Activities, Services, and/or BroadcastReceivers and Android System will put a right to kill your process.
Post a Comment for "System.exit(0) Causes The Activity Quit Quickly When The App Starts"