3

In android finish(); is used to close the Current activity. In my application i've more than 4 Activities. I want to finish them with one single statement. How can i done this here.

I've tried the System.exit(0); it's not working for me. Why this not working for me also? Anyone guide me here? Thanks in Advance.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
  • System.exit(0) should never be used because it destroys the activity lifecycle and shutsdown the application immediately. – L7ColWinters Jan 18 '12 at 05:10
  • 1
    when launching a new `Activity`, use `startActivityForResult`, set the result in `onDestroy` of each `Activity`, such as `setResult(-1)`, then in `onActivityResult`, `if (resultCode==-1) { finish(); }` – Phil Jan 18 '12 at 05:10

3 Answers3

2

Use following set of instructions.

Intent intent = new Intent(getApplicationContext(), Home.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Community
  • 1
  • 1
jeet
  • 29,001
  • 6
  • 52
  • 53
2

Its better to always go back to homeActivity by using startActivity of your home screen. you can find answers here. How to close all the activities of my application? and Is quitting an application frowned upon?. its already discussed here

Community
  • 1
  • 1
AD14
  • 1,218
  • 19
  • 32
1

I've got the answer. I've give the moveTaskToBack(true); to my Button Click event. This works fine. Thanks for you all whose reply me and answer me.

Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
  • this is not finishing your, activity what you asked. it is just sending your app in back, when user long press on home button ur app will resume where you left it. – AAnkit Jan 18 '12 at 05:21
  • @AnkitA Yes you're right. It pause the last state. Okay, i'll try another answers – Praveenkumar Jan 18 '12 at 05:51
  • do one thing, if you do not want to save your activity states, add exclude from recent tag in xml in your activity, second thing make your question more generic so every body can know what you are going to achieve. let me know if i can help, – AAnkit Jan 18 '12 at 05:55