4

when i click a button my app should be terminated. It must not to run at the background. that is when holding the home key, My App should not be alive. For Example, i have to redirect my app to the browser. then My App goes to as a background Task. I want to terminate before the redirection to browser. How is it Possible? Any Idea? Better I would need a Explanation on that. that helps to understand How it works to EveryBody.

Thanks in Advance.

Praveen
  • 90,477
  • 74
  • 177
  • 219
  • 1
    just an annotation: when holding the home key the recently used applications are shown - that doesn't necessarily mean that these applications are still running in the background – DonGru Aug 18 '10 at 11:47
  • possible duplication of http://stackoverflow.com/questions/6330200/how-to-quit-android-application-programmatically – Oded Regev Jan 03 '12 at 13:05
  • Don't kill your app. If you do not want them to appear in the last recent app list, then add android:excludeFromRecents="true" to your manifest. – JacksOnF1re Jun 10 '16 at 10:15

3 Answers3

4

http://developer.android.com/guide/topics/fundamentals.html#clearstack

The finishOnTaskLaunch attribute
This attribute is like clearTaskOnLaunch, but it operates on a single activity, not an entire task. And it can cause any activity to go away, including the root activity. When it's set to "true", the activity remains part of the task only for the current session. If the user leaves and then returns to the task, it no longer is present.

.. or something like this. I'm new to android, and had just past this part of the docs, and I thought it might help.

EDIT: maybe call finish() in onPause()?

Thom Wiggers
  • 6,938
  • 1
  • 39
  • 65
  • 1
    finish() does just finish the current Activity. if we set the attribute to the tag. its globalize for the whole app. i want to just when click the button it shuts off. like Task Manager App. Any Other Idea to do that by Programmatically not in Manifest? – Praveen Aug 18 '10 at 11:40
  • 2 ways: build the functionality to kill a task like a task manager or ignore it. Thats how Android was designed... it takes care of itself, no real need to "finish" an application. – WarrenFaith Aug 18 '10 at 11:56
0

What i did is launch the activities with startActivityForResult(), and then, when i want to finish the application, set a result and finish(). Later, i got that result with:

public void onActivityResult(int requestCode, int resultCode, Intent data){...}

And if i got the expected result, finish that activity setting a new result for the previous one.

That works for me, but it's easy because i only have two previous activities in my case...

Horaceman
  • 786
  • 6
  • 10
-3

Like the answer above already said:

finish();
return;

Good luck
Tom

TomTasche
  • 5,448
  • 7
  • 41
  • 67