Mark, Thanks for the great explanation! It worked like a charm.
Mark On Mon, Mar 19, 2012 at 5:27 PM, Mark Murphy <[email protected]>wrote: > On Mon, Mar 19, 2012 at 8:13 PM, Mark Phillips > <[email protected]> wrote: > > If I click on Help, then Preferences, then Help, then Preferences, then > > Help, and then go back, I have to go back through the whole chain to get > to > > my starting point. I seem to be creating several HelpActivities and > > PreferenceActivities as I go (I put a toast message in each activities > > onCreate method to tell me when the activity is created). This behavior > does > > not seem to be a good idea. So, my question is: in the > onOptionsItemSelected > > method for the HelpActivity, how do I determine if there is an existing > > PreferenceActivity and go to that one, or create a new one if there isn't > > one. I would think there must be some Android pattern for this problem, > as I > > can't be that clever to be the first one to run into this problem. > > You can add FLAG_ACTIVITY_REORDER_TO_FRONT to your Intent you use with > startActivity() for all but perhaps your "home" option. This flag will > "recycle" an existing instantiated copy of your activity, if one > exists (otherwise, it creates one). > > In this case, if you "click on Help, then Preferences, then Help, then > Preferences, then Help", BACK will take you to Preferences, and > another BACK will take you wherever you started from. > > For the "home" option, you might instead add FLAG_ACTIVITY_CLEAR_TOP > and FLAG_ACTIVITY_SINGLE_TOP flags to your Intent for startActivity(). > This destroys all other activities in your task and then displays the > one you are starting. > > In this case, if you clicked on Help, then Preferences, then the > action bar's home affordance, then BACK, you exit the application -- > the home affordance would wipe out the Help and Preferences activities > via the aforementioned pair of flags, leaving you with just your home > activity, which BACK would exit. > > -- > Mark Murphy (a Commons Guy) > http://commonsware.com | http://github.com/commonsguy > http://commonsware.com/blog | http://twitter.com/commonsguy > > Android Training in NYC: http://marakana.com/training/android/ > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

