How to exit from an android app?

醉酒当歌 提交于 2019-12-10 21:08:20

问题


I've just read that you can exit an android application by simply calling:

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!


回答1:


You might want to look at Quitting an application - is that frowned upon? thread here in SO.




回答2:


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.



来源:https://stackoverflow.com/questions/4617049/how-to-exit-from-an-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!