I have an activity ABCDE

I need to close the activity CDE when the user has moved from E to B. Tobish the user opens the CDE after goes to B and at this point you need to close the CDE.

Should remain A B. If the user in C or in D, then you do not need to close anything

PS I read my question and remembered computer science problems))

  • Activations do not need to be closed specifically, they will do it themselves when the system deems it necessary. Maybe you need to clear the transition stack, so that from B to "back" you do not return to E? or what is the purpose of these closures - pavlofff
  • @pavlofff, Yes, but I would like A not to close. After all, if you clear the stack. then Activity A off ... - Andro
  • Actually it is possible, but you do not have the accuracy of the transition in question. What you want to do is done by calling the arrays of activities and the flag single-top, and then you need to look at each case separately. - Shwarz Andrei

1 answer 1

If the user goes "from E to B", then this means that B is started by Intent. Add the Intent.FLAG_ACTIVITY_CLEAR_TOP flag:

Intent a = new Intent(this, B.class); a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(a); 

For example, consider the circumstances: B, C, D, B, C, D, C then D , resulting in the stack now being: A, B.

Immediately note that the new intent will come in onNewIntent (), and getIntent () will return the intent with which the activation was launched the first time.

  • Did you read the topic at all? I wrote that this approach is not suitable because it erases Activity A !! - Andro
  • Does not wash. Added a quote from the documentation, it is fully consistent with the question. You are probably confusing with FLAG_ACTIVITY_CLEAR_TASK. - tse