0

OK so I have done some research and it looks like there are a fair amount of questions regarding this (such as here) but none of the answers seem to address my particular question.

Simply put, say we have back stack with three activities: A -> B -> C. Now if the user performs a certain action in activity C (the foreground activity) I want to be able to remove activity B from the back stack and replace it with some other activity D giving A -> D -> C. Is there any way to do this without disrupting activity C?

Thanks in advance.

Community
  • 1
  • 1
Kent Hawkings
  • 2,793
  • 2
  • 25
  • 30
  • 2
    AFAIK, there is no way to do this. Good you give an example of why you would need this and maybe we can help find a solution? – codeMagic Sep 05 '13 at 12:55
  • 1
    To delete B from the back stack look at [this](http://stackoverflow.com/questions/5001882/how-to-clear-specific-activity-from-the-stack-history?answertab=votes#tab-top). If the foreground activity is C you can override the function `onBackPressed()` (executed when the back button is pressed) and start the activity D. – AlexBcn Sep 05 '13 at 12:56

1 Answers1

-1

OK so there seems to be no way to do this as I initially envisioned. Thanks to the suggestion given by @AlexBcn in a comment I did find a somewhat "hacky solution". When the user is in activity "B" (so the stack is currently A -> B) and presses a button causing activity "C" to start we destroy activity B. So our stack is now A -> C. I then keep track of what "state" activity C is in (as this determines what I want the previous activity to be). I then override the onBackPressed method such that when activity C is destroyed a new activity is created (i.e. activity "D") to replicate my desired effect.

Kent Hawkings
  • 2,793
  • 2
  • 25
  • 30