How to force close the app when using multiple activity
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 tr开发者_运维百科ied system.exit
it kills that particular activity and go back to previous activity. please guide me to solve this..
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..
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
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.
If you want to kill or stop your app, you can try this,
int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);
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);
..
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
精彩评论