0

I have a problem with my app. I really need to kill it when user clicks "Exit". I've tried both methods listed in the question header, and here's the problem: I have a persistent (foreground) service performing work, so there is a tray icon for my app. When user switches to my app via this icon and then presses "Exit" - the app is kill, but Android immediately restarts it. If the users switches back to the app using any other method (not the service icon) - application is not restarted upon exit.

So, what is the reliable way of killing application?

P. S. There's always only one activity in the application, if that is of any importance.

Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335
  • possible duplicate of [Quitting an application - is that frowned upon?](http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon) – CommonsWare Dec 01 '11 at 14:55

3 Answers3

0

for only one Activity, I choose finish().

Pete Houston
  • 14,931
  • 6
  • 47
  • 60
0

You can use following intent to exit from your activity

Intent startMain = new Intent(Intent.ACTION_MAIN);
          startMain.addCategory(Intent.CATEGORY_HOME);
          startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          startActivity(startMain);

and Call finish() before you call this intent.

bindal
  • 1,940
  • 1
  • 20
  • 29
-1

I have found the solution to my problem. If I move my activity to background with moveTaskToBack(true); and then kill the process it is not restarted.

Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335