问题
I have an activity that handles search requests with the SearchManager and it's working just fine. Let's call this activity MySearchActivity.java. The problem is that within this activity, I have a button that invokes the search request dialog with a call to onSearchRequested().
If MySearchActivity.java is the current task in the activity stack and the user taps the icon within this activity that calls onSearchRequested(), this activity is re-launched on top of itself. So within the activity stack, I have two of the same activities on top of each other.
I don't want to use android:noHistory in the manifest for this activity, and can't find any other suitable flags for what I'd like to accomplish.
I would like that if the user taps the icon in MySearchActivity.java which invokes the call to onSearchRequested(), that the activity not duplicate itself in the stack.
I know I'm probably overlooking something or making this more complicated than it really is....any ideas?
回答1:
For the solution you probably have to set launch mode to "singleTop" for activity (e.g android:launchMode="singleTop"). Here is the further explenation @documentation. Good luck!
来源:https://stackoverflow.com/questions/8936971/call-to-method-onsearchrequested-in-the-same-activity-that-handles-search-requ