Android app exit, which Mechanism to use?
following are the ways to exits from the application
1. ActivityObject.finish();
2. Runtime.getRuntime().exit(0);
I want to know which way is to be used & when ?
if there is another way please let 开发者_开发百科me knowThanks in advance. Shrenik
That's usually not a good idea at all to "exit" an application in android. That's against Android nature. Read this topic first before doing something like that.
Look at this life cycle of an Android activity:
And the description of the OnDestroy state:
The final call you receive before your activity is destroyed. This can happen either because the activity is finishing (someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method.
So calling ActivityObject.finish() is the right way to do it.
call moveTaskToBack(true) on your Activity
精彩评论