Android activates a new action, clearing others

I have a series of actions A, B, C, which, upon completion, should push the new activity Y to my home activities. The task stack should look like this.

  • N
  • H-> A
  • H-> A-> B
  • H-> A-> B-> C
  • H-> Y

I need a back button to be able to return from C back to B or B back to A, but then C is done. I need Y to be an active task. And "back" from Y you need to go home (H).

Thanks.

+4
source share
2 answers

Jamie, are you doing Android now? What a terrible thought! In any case, finish() is your friend when it comes to removing actions from the stack. You can call it several times to pull several actions from the stack.

Alternatively, you can also delete the entire stack by passing the FLAG_ACTIVITY_CLEAR_TOP flag in your intent (but it looks like you want to keep H, so this might not be a smart choice).

By the way, one thing I haven't played with is FLAG_ACTIVITY_NEW_TASK, but that might work in your case. Pass it on before starting A This can be completely useless in your case, so just experiment a bit with it.

EDIT: played around a bit with it, causing completion () several times, actually not working properly. I got it to work by running H with FLAG_ACTIVITY_CLEAR_TOP, and then Y right after that (i.e. Two startActivity in one function).

+1
source

You can run the FLAG_ACTIVITY_CLEAR_TOP flag to activate H This would call the onNewIntent() method of H. activity. You could install the appropriate add-ons in this intent and use them to run Activity Y

+2
source

All Articles