3

I am customizing quick search to display data from my app. Its working fine. Now the issue is, When I click on search button, I am not able to see the search history. What should I do get the search history (previously searched keywords)?

halfer
  • 19,824
  • 17
  • 99
  • 186
Padma
  • 656
  • 3
  • 11
  • 30

1 Answers1

2

If you go through the tutorial on developer.android.com, I think you will find what you are looking for:

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

The trick is to implement a ContentProvider which extends SearchRecentSuggestionsProvider. It's a simple class:

public class MySuggestionProvider extends SearchRecentSuggestionsProvider {
  public final static String AUTHORITY = "com.example.MySuggestionProvider";
  public final static int MODE = DATABASE_MODE_QUERIES;

  public MySuggestionProvider() {
      setupSuggestions(AUTHORITY, MODE);
  }
}

Remember to add your provider to the manifest, and update your searchable.xml file so that it knows of your provider:

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
  android:label="@string/app_label"
  android:hint="@string/search_hint"
  android:searchSuggestAuthority="com.example.MySuggestionProvider"
  android:searchSuggestSelection=" ?" >
</searchable>

Also you will need to save the searches in your searchable activity:

if (Intent.ACTION_SEARCH.equals(Intent .getAction())) {
  String query = Intent .getStringExtra(SearchManager.QUERY);
  SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
      MySuggestionProvider.AUTHORITY, MySuggestionProvider.MODE);
  suggestions.saveRecentQuery(query, null);
}
Eric Nordvik
  • 14,656
  • 8
  • 42
  • 50
  • hi thanks for ur reply, I have tried this, the prob i got is, my normal suggestion itself is not working. That is, now searching my database using quick search is perfectly working for me, only recent suggestions are not coming when i click on search button. Now I have a provider which extends ContentProvider. Do i need to change the same provider or i should use the seperate provider which extends the SearchRecentSuggestionsProvider. Thank u so much for ur reply. – Padma Nov 26 '10 at 06:38