2

I am working on an Android application which has logout button. When I click on that I need to close my app completely (I don't want to run the app in background as well).

I tried with System.exit(0) and finish() as well.

5
  • "When I click on that I need to close my app completely (I don't want to run the app in background as well)" -- why? Commented Feb 19, 2013 at 12:23
  • @CommonsWare, That is log out button and the session should expire. That is reason I need to close it permanently Commented Feb 19, 2013 at 12:42
  • can u share ur androidmanifest file ? is <application android:killAfterRestore="true"> Commented Feb 19, 2013 at 12:42
  • @PowerPc, I added this but no use Commented Feb 19, 2013 at 12:49
  • 1
    "the session should expire" -- this has nothing to do with "close my app". Do you think Web developers try to crash the user's browser to "close my [Web] app"? Commented Feb 19, 2013 at 12:53

3 Answers 3

4

on your logout button try this code:

 finish();
 moveTaskToBack(true);
 System.exit(0);

i think this will not close your app completely but will exit from all of the activities.

Sign up to request clarification or add additional context in comments.

Comments

0

the finish()-method runs the destruction of the activity. so, it should be right here.

1 Comment

Thanks for the response, finish(); is not working for me.
0

Android has a mechanism in place to close an application safely.

In the last Activity on the stack (usually the main, or just the first you have started) override the onDestroy() method.

You can either call the System.runFinalizersOnExit(true) which ensures that all objects will be finalized and garbage collected when the the application exits, or kill an application quickly via android.os.Process.killProcess(android.os.Process.myPid()) if you prefer.

1 Comment

I tried with following code. But no use android.os.Process.killProcess(android.os.Process.myPid());

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.