Keep different search histories for different activities?

帅比萌擦擦* 提交于 2020-01-01 05:36:14

问题


I have two activities, and I'd like them to each maintain their own search history suggestions. Is that possible? They each have their own search suggestion provider, but I see the same search history appearing for both activities:

// manifest.xml
<activity
  android:name="ActivityA"
  ...
  <meta-data 
    android:name="android.app.searchable"
    android:resource="@xml/searchable_A" />
</activity>

<activity
  android:name="ActivityB"
  ...
  <meta-data 
    android:name="android.app.searchable"
    android:resource="@xml/searchable_B" />
</activity>


// searchable_A.xml
<searchable   
  android:searchSuggestAuthority="providerA" />

// searchable_B.xml
<searchable   
  android:searchSuggestAuthority="providerB" />

When saving the search suggestions, I'm making sure to use the correct provider for each activity.

// ActivityA.java
SearchRecentSuggestions suggestions = new SearchRecentSuggestions(ActivityA.this,
    providerA.AUTHORITY, providerA.MODE);
suggestions.saveRecentQuery(...);

// ActivityB.java
SearchRecentSuggestions suggestions = new SearchRecentSuggestions(ActivityB.this,
    providerB.AUTHORITY, providerB.MODE);
suggestions.saveRecentQuery(...);

Since the search suggestion providers are different, I was expecting them to each maintain a different history. The use case here is that I have an Activity dedicated to cars, and an Activity dedicated to foods. I don't want past search terms to be mixed together, they don't make sense in the different contexts.

http://developer.android.com/guide/topics/search/adding-recent-query-suggestions.html

来源:https://stackoverflow.com/questions/8510169/keep-different-search-histories-for-different-activities

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