0

I am starting a new activity with thsese flags

finish_intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);

when i close the activity it resumes the activity before that how can i close all the activities ?

opc0de
  • 11,557
  • 14
  • 94
  • 187
  • This question was asked before: [see here][1]. [1]: http://stackoverflow.com/questions/9535272/android-finish-method/9536435#9536435 – ThisIsNotMe May 17 '12 at 15:28

2 Answers2

0

when you move from the 1st activity to the next activity , the previous activity gets saved on the back stack, this adds the overhead, as objects of same activity are created again when u return back to the previous activity. So you can use the method finish() to kill the 1st activity when moving to the 2nd.

eg:

Intent i = new Intent(this,Myapp.class);

startActivity(i);

finish();
Kumar Vivek Mitra
  • 33,294
  • 6
  • 48
  • 75
  • But i want to keep other activities in case the user presses the back button. Only on the final activity i want to close all running activities! – opc0de May 17 '12 at 12:10
  • Its BackStack, which means, when u open the 1st activity it gets added to the backstack, then when u move on to the 2nd activity its the 2nd activity added to the backstack, so using finish() method in the 2nd activity, you are removing the 2nd activity from the stack, and u fall on the 1st activity. You can try using finishActivity() method. – Kumar Vivek Mitra May 17 '12 at 18:04
0

When starting a new activity finish the previous one

Intent i = new Intent(this,CLASSTOLAUNCH.class);

startActivity(i);

finish();