0

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..

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
RAAAAM
  • 3,378
  • 19
  • 59
  • 108

6 Answers6

1

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

MightyPork
  • 18,270
  • 10
  • 79
  • 133
Davlik
  • 39
  • 3
1

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..

ngesh
  • 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
0

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.

Dayerman
  • 3,973
  • 6
  • 38
  • 54
0

If you want to kill or stop your app, you can try this,

    int pid = android.os.Process.myPid();
    android.os.Process.killProcess(pid);
Andro Selva
  • 53,910
  • 52
  • 193
  • 240
0

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);..

ngesh
  • 13,398
  • 4
  • 44
  • 60
0

I also thought that. But I think shouldnt be right...Better to send the result to the previous activity. But Also I think closing the application from any activity is not the way Android is design. Have a look here

Community
  • 1
  • 1
Dayerman
  • 3,973
  • 6
  • 38
  • 54