3

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!

ingh.am
  • 25,981
  • 43
  • 130
  • 177
  • possible duplicate of [Android App Exit Button](http://stackoverflow.com/questions/4089496/android-app-exit-button) – fredley Jan 06 '11 at 16:20

2 Answers2

5

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

Community
  • 1
  • 1
jhurtado
  • 8,587
  • 1
  • 23
  • 34
  • 2
    +1 - Commonsware's answer in that question should be required reading for any new Android developer. – Erich Douglass Jan 06 '11 at 16:42
  • Yea I did give that a read through. Have just been looking at this http://developer.android.com/reference/android/app/Activity.html which helps explain how the cycle runs... – ingh.am Jan 06 '11 at 16:59
1

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.

cesarislaw
  • 1,589
  • 1
  • 11
  • 21