jeudi 14 mai 2015

Passing activity result back to grandparent activity (not parent)

I have a situation in which I have 3 activities.

  1. ResultsActivity
  2. SimpleSearchActivity
  3. ComplexSearchActivity

The flow works as follows: The user can choose to search from the ResultsActivity which will launch the SimpleSearchActivity. From there the user can perform a simple search. The result is pass back to the Results activity.

However from the SimpleSearchActivity the user can choose to do a complex search which will finish the SimpleSearchActivity and launch the ComplexSearchActivity. From there I want to pass the result back to the ResultsActivity. I am not sure how to do this since this 3rd activity was not launched from the first activity, but the second.

Options I have considered:

  1. In complex search case go back to ResultsActivity and launch the ComplexSearchActivity from there. Not sure I really want this as I don't want the SimpleSearch to close go back to the Results then immediately launch the Complex. I am worried this will 'flash' the ResultsActivity before launching the ComplexSearchActivity.

  2. In complex search case, from SimpleSearch launch ComplexSearch with startActivityForResult(...), on complex finish the simple search can grab the result, then pass that back to the Results activity. I am not sure this chaining will work. Even if it does I am worried that on complex finish the SimpleSearchActivity will 'flash' just to pass the results back.

  3. Store the search results in a static variable somewhere and on ResultsActivity launch just check for that static variable that might have been set by either search activity. Yuck!

  4. I have also thought of only having one search activity and doing a show/hide on certain fields (simple vs complex). However I launch the simple search as a dialog activity (in tablet case) and complex search as full screen activity. So I cannot really use the same search activity.

Ideas? Has anyone tried something like this before?

Aucun commentaire:

Enregistrer un commentaire