How to quit the app or force close the app when multiple activity running in background. I tried to give system.exit(0)
, but this will works only having single activity. In my app i have 3 activity when i tried system.exit
it kills that particular activity and go back to previous activity. please guide me to solve this..

- 53,910
- 52
- 193
- 240

- 3,378
- 19
- 59
- 108
6 Answers
Hello u can use your System.exit(0);
if u call your next activity onClick //
Intent i = new Intent(getApplicationContext(), YOURActivity.class);
startActivity(i);
System.exit(0);
It just force close your app and reopen called activity..
Not the right way but its working x)
Atleast for me when i had problem with multiple activity with gps location

- 18,270
- 10
- 79
- 133

- 39
- 3
while starting Activity call startActivityForResult();
and in the same class override method onActivityzResult()
and call finish();
inside it.. do the same in all other activities..

- 13,398
- 4
- 44
- 60
-
Thanks, i cant understand where to put onActivityResult() and finish(). whether to put in same class (while calling activity) or inside the calling class..?? – RAAAAM Jun 16 '11 at 07:17
-
I have given this, but existing activity is not closed.. I gave startActivityForResult(); in calling class, and onActivityzResult() in both the class inside that i given finish. but nothing is happened.. – RAAAAM Jun 16 '11 at 07:40
-
then try to kill it using system.exit() in places where u ve put finish() or add "int pid = android.os.Process.myPid(); android.os.Process.killProcess(pid);" in place of finish() like selva said – ngesh Jun 16 '11 at 07:44
-
can you give some example link to understand this issue. i tried so many times but nothing is happened. I hope i cant able to understand what you mentioned above.I am new to android can you pls guide me. – RAAAAM Jun 16 '11 at 07:57
You can use startActivityForResult, and then when the activity on the stack finish, sends a integer back to the previous activity, there you can do the same until you finish the 1st activity.

- 3,973
- 6
- 38
- 54
If you want to kill or stop your app, you can try this,
int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);

- 53,910
- 52
- 193
- 240
Another dummy idea is u can create another dummy activity and just add finish method in it.. and in your 3rd activity start this activity with intent as intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
..

- 13,398
- 4
- 44
- 60