tags:

views:

50

answers:

2

I'm making an app which has a flow roughly as below:

  1. User starts on the main screen with an empty list, hits menu, and goes to "add item." (Activity A)
  2. User is given a new activity which allows them to specify search criteria, then hits "go" to do a search. (Activity B)
  3. User gets a list of results, and can click on one of them to view more details. (Activity C)
  4. User sees details of item, and can use a menu item to save it to their list in Activity A. (Activity D)

Right now, I am having each Activity call each other Activity for results, and then it is passing the result all the way back up the stack as it returns to Activity A. Is there a way to jump this, since all I want is for a result in Activity D to get to Activity A directly?

Note that a user should still be able to navigate backwards (using the back button) through each activity, but if they explicitly save the item in Activity D, I want it to jump straight to Activity A.

+1  A: 

I recommend just invoking the activities (not using the *ForResult) calls, then having activity D invoke Activity A with an INTENT_ADD_ITEM with data, then have Activity A add the item.

Hope this helps...

Scott
A: 

Just so that people can benefit from what I learned later...

The key to solving this problem is using flags with Intent, in this case using FLAG_ACTIVITY_CLEAR_TOP. Other flags are useful as well in controlling the flow of your UI.

It is a bad idea to try to solve this problem by chaining startActivityForResult() through activities. It means that it's difficult to change the flow of your application.

Daniel Lew