Reputation: 24583
I have a situation in which I have 3 activities.
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:
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.
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.
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!
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?
Upvotes: 1
Views: 501
Reputation: 3665
Have you think about the approach the abstract the data layer to be shared across all activities rather than to have only certain activity to hold the data?
Upvotes: 0
Reputation: 3137
There are a couple ways you can achieve this:
Option 1: You can choose not to close SimpleSearchActivity
when you launch ComplexSearchActivity
. Instead, have ComplexSearchActivity
send its result back to SimpleSearchActivity
, and from there have SimpleSearchActivity
pass that result to ResultsActivity
.
Update: This will, at least in my experience, have no UI "flash"; it should appear seamless.
Option 2: Use FLAG_ACTIVITY_FORWARD_RESULT, which exists for exactly this purpose.
Upvotes: 2