问题
I have an application which I would like to be fully disabled/closed when it is paused (IE. When the user presses the Home, End (call) and Back button I would like the application to be closed, instead of being saved in the history stack).
How do I do this....?
Thanks.
回答1:
Implement onPause()
in your activity and call finish()
on your activity. Bear in mind, though, that this will occur on every pause, including dialogs, incoming calls, users activating a Notification
. You might want to consider doing finish()
in onStop()
, which would at least solve the dialog problem.
Also, bear in mind that users will may get confused when using your app, thinking it has crashed since it is gone when they try to get back to it.
回答2:
you can easily do that by setting true the "noHistory" attribute in to your activity element, in the manifest
http://developer.android.com/guide/topics/manifest/activity-element.html#nohist
回答3:
You know how you have an OnCreate() method in your activity which performs actions when you start. You need to add something like:
@Override
protected void onPause(){
finish();
super.onPause();
}
in your activity to add actions before it starts
in this case the
finish();
command is what you want to execute before your activity pauses.
来源:https://stackoverflow.com/questions/1024803/killing-android-application-on-pause