java 如何退出安卓应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4617049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to exit from an android app?
提问by ingh.am
I've just read that you can exit an android application by simply calling:
我刚刚读到您可以通过简单地调用来退出一个 android 应用程序:
finish();
However this is not the case! When I do this I get the following errors:
然而,这种情况并非如此!当我这样做时,我收到以下错误:
PackageInstallationReciever Remove /data/local/tmp/com._____.apk Fail!
AndroidRuntime Uncaught handler: thread main exiting due to uncaught exception
AndroidRuntime java.lang.NullPointerException
AndroidRuntime at android.....
dalvikvm Unable to open stack trace file '/data/anr/traces.txt': Permission denied
So what is the proper way to force an application to exit? For the record, I'm calling it from a menu item but it doesn't seem to matter!
那么强制应用程序退出的正确方法是什么?为了记录,我是从菜单项中调用它的,但这似乎无关紧要!
回答by jhurtado
You might want to look at Quitting an application - is that frowned upon?thread here in SO.
您可能想查看退出应用程序 - 这是否令人不悦?线程在这里。
回答by cesarislaw
What are you trying to accomplish with an in app exit? If you want the app to not save state after the user exits you can add this flag to the main activity in the manifest file:
你想通过应用内退出来完成什么?如果您希望应用程序在用户退出后不保存状态,您可以将此标志添加到清单文件中的主要活动:
android:clearTaskOnLaunch=true
This will clear the activity stack when the application is reopened.
这将在重新打开应用程序时清除活动堆栈。