0

I have a situation like this

I'm using a single activity but with different parameters so I assume that they are seperate activities

This is a navigation sequence

A-B-C-D-E-F, and in F I have a view that takes me to the C, or sometimes B. What I want is when I press back button, the activity must take me to my stack rather than system stack, or when I navigate back to an earlier stack it should pop activities rather than pushing them. How can I do that?

Note: I'm using a single Activity so I need to use the standart launch mode. What I need is to be able to remove Activity instances from stack to the place I navigate

ikbal
  • 1,844
  • 4
  • 26
  • 46

2 Answers2

2

Use Intent flags and launch mode - look at this free app to help you work out easily what different flags and modes do: https://market.android.com/details?id=com.novoda.demos.activitylaunchmode

See this page for more help : http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html

Martyn
  • 16,432
  • 24
  • 71
  • 104
  • Thank you for your answer Martyn but I think my situtation is a bit different. My activities are not seperate they are all the same activities. I have MyActivity class and navigate to another instance of MyActivity each time. So when I use launch mode or intent flags it doesn't work. I need to do something like that "pop n activities from top of stack" without starting any of them – ikbal Oct 17 '11 at 07:41
  • I don't think there's a way to manage the stack dynamically in terms of being able to pop n activities - your best bet is to look at Intent Flags - these are defined at runtime, not in the manifest file like the launch modes - and see if you can intelligently work out how to achieve the same result with some forward planning? – Martyn Oct 17 '11 at 07:52
  • Actually I didn't find a way to achieve with activity stack popping. As I said earlier I work on a single activity so when I try to clear top, all of my activities are popped. I'm trying to override on back key press and onResume events, but seems very unnatural – ikbal Oct 17 '11 at 17:29
1

You should use INTENT_FLAGS or LAUNCH_MODE to manage your task stack. Also you can use ActivityGroup class and manually manage activities into this group by your parameters and other conditions.

Georgy Gobozov
  • 13,633
  • 8
  • 72
  • 78