Call to method onSearchRequested() in the same activity that handles search requests causes duplication in activity stack

不打扰是莪最后的温柔 提交于 2019-12-23 17:17:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!