views:

1492

answers:

1

I have 3 Activities that my user continuously is looping through. When user is back to the main screen I need to terminate previous history so user cannot hit back button and end up on screen #2, what would be a good way to do something like that? BTW - I'm using 1.6 (API level 4)

To reiterate - say I don't know or predict the path which leads me to the original view. But once I load it I want to clear history that led user to that view. In 2.0 it's possible with overwriting Activity#onBackPressed but I need something like that in 1.6

+2  A: 

See ApiDemos sample application: App -> Activity -> Forwarding, Redirection and Reorder Activities

Bakhtiyor
These are very nice snippets but what do they have to do with the problem I described?
DroidIn.net
It's not clear the flow of activities from description. Suppose it's circular and looks like 1 -> 2 -> 3 -> 1 -> 2 -> 3, and you want to restrict going back from 1st activity to 3rd.Use "Forwarding" tech­nique to call 3rd activity, to return to 1st just finish 3rd activity. If you need pass some data use result codes.If my comment is not clear to understand install ApiDemos app and go through samples there.
Bakhtiyor
1->2->3 normal3->2 back button then there's menu option that takes you back to 1At this point I can press back button and go to screen 2I suppose I can just add Activity#finish() when user goes back to 1st screen by pressing the menu option. Now - the question I have: the navigation history has to be stored somewhere. It would be great if I can call something like `Activity#clearHistory` but obviously such method does not exist
DroidIn.net
See Intent flags: set FLAG_ACTIVITY_CLEAR_TOP to "clear" history.
Bakhtiyor
Aha! I think this may work! Thank you
DroidIn.net