2

I have an app with more than 4 activities, but when somebody wants to exit the app, he gets all the activities again. Now i've tried to use exit codes:

this.finish()
android.os.Process.killProcess(android.os.Process.myPid())

etc.

But nothing helps me, so my question is, is there an way to kill all the activities at one time, like a task killer?

Edit:

I've found it on myself:

When you launch the second activity, finish() the first one immediately:

startActivity(new Intent(...));
finish();
Gaauwe
  • 281
  • 2
  • 8
  • 18
  • 1
    When do you want it to be killed? It sounds like you expect the application to close when the user presses "Back," but instead they are taken through previous activities. If this is the case, simply call `finish()` on all of the Activities when you launch a new one. Implementing an Exit button or kill button doesn't mesh well with the operating system. – LeffelMania Jul 25 '11 at 17:52
  • possible duplicate http://stackoverflow.com/questions/2042222/android-close-application – jamapag Jul 25 '11 at 17:56
  • 1
    What you're suggesting at the end isn't really doing what you asked. It's just finishing the previous activities so you can't go back. You can accomplish the same thing by setting "No History" to true in the manifest file. – DeeV Jul 25 '11 at 18:11

2 Answers2

1

Does System.exit(0) do the trick?

Jayp
  • 782
  • 2
  • 6
  • 21
  • No, the app will bring you to the last activity and than again to the last activit and again and again and than he exit the app, like you press the back button – Gaauwe Jul 25 '11 at 17:56
0

Try getParent().finish() where you catch the back button; getParent() returns the activity that called current activity. And if you finish the parent, you finish the child. Also you can make start the activities for result and then pass something in the intent data on which you'll test and finish each activity one by one. I'm not sure if this is the best and working solution.

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148