问题
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