问题
How to shutdown an android application? I don't find a shutdown command to application object. I want to shutdown and restart in case of some critical error.
回答1:
If there is some kind of "critical error", then you should should deal with it in your code rather then trying to restart the application.
You cannot shutdown an application in Android, however once all of your Activities are closed (which you can programatically do with the Activity.finish() method), then your application is considered to be closed.
回答2:
You don't need to shutdown an application, Android takes care of this.
The application is on the background and she is "freezed". If the system, or another application needs memory or CPU, Android will choose a background application to stop.
But everything is automatic. It's the Android's power !
回答3:
Here's a more in depth answer about quitting applications: Is quitting an application frowned upon?
Agree with elevine on handling errors...either deal with the error and get the user back to an acceptable state or let the app force close.
回答4:
To shutdown an activity
you can use like told by other with finish()
. If you want to force to terminate your app including all threads and the Application
class you can use System.exit()
, but that had some bad favior which I forgot...
回答5:
To terminate an activity, call finish()
. To restart it, just call the intent again.
来源:https://stackoverflow.com/questions/8548448/how-to-shutdown-an-android-application