Proposed Alternative to implementing handling queries


My proposal is to used the OnQueryTextListener() of the SearchView method instead of overriding onNewIntent.

In Listing 28.15, implement onQueryTextListener after setSearchableInfo. Now you can listen for queries when the user submits a search or while entering a search query. onQueryTextSubmit provides the same effect as Listing 28.9 onNewIntent.

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(, menu);
// Pull out the SearchView
MenuItem searchItem = menu.findItem(;
SearchView searchView = (SearchView)searchItem.getActionView();

        // Get the data from our searchable.xml as SearchableInfo
        SearchManager searchManager = (SearchManager)getActivity().getSystemService(Context.SEARCH_SERVICE);
        ComponentName name = getActivity().getComponentName();
        SearchableInfo searchInfo = searchManager.getSearchableInfo(name);
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            public boolean onQueryTextSubmit(String s) {
                return true;

            public boolean onQueryTextChange(String s) {
                return true;