views:

28

answers:

1

I have a reservation wizard in android, when i say wizard i mean i have multiple activities (meaning screens) that are passed from one to another until booking is complete. in each step of the way my info may be invalid and so ill have to back track 2-3 activities and start all over, all the activities i back tracked should be destroyed, they may need to invalidate a singletone data container that they filled with their data. I thought of 2 ways to do this:

  1. start all activities related to the wizard with startActivityForResult() so i get notification when an activity is finished and with which error code (finished ok or error occurred) and act accordingly (for instance: if in the middle an activity fails it will return failed and the previous one will return failed as well until i get to the wizard's first activity where i either declare the error with a dialog or show the 'thank you' screen.)
  2. I can send an react on intents with certain parameters so i have a 'close and clean' intent message that close down the previous activity etc...

which way is better, any other interesting\efficient way to do this ?

A: 

I Got a hint that got me thinking in a different direction:

  1. use an invisible Activity, or alternatively , a local service,that is the 'brains' that known on each turn of the way what action is to be taken. to remove a complete stack of unneeded activities i should use the FLAG_ACTIVITY_CLEAR_TOP on the bottom most activity i want to use next.
  2. Another options is to enclose all the activities i want to play with their pposition on the stack inside an ActivityGroup Object which keeps all activities alive (like in Tab) and on the stack, but you control which one is displayed and which is not. the activity group will contain the state machine logic regarding which Actvity should not be displayed and which should be disposed.
codeScriber