I have an activity that contains a SearchView widget. I am handling the results of the text search using an onQueryTextSubmit listener, and this works fine. (The activity itself is designated as a Searchable Activity).

I recently decided to add voice recognition, by adding the "voiceSearchMode" attribute in the searchable.xml file:

searchable.xml

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/app_name"
    android:hint="@string/search_hint"
    android:voiceSearchMode="showVoiceSearchButton|launchRecognizer">
</searchable>

When I added the voice recognition, the onQueryTextSubmit listener does not get called after providing the voice input (however, it still gets called after providing the text input using the editText box). The voice recognizer sends an ACTION_SEARCH Intent back to the same Activity (which can be handled in the onCreate method). Is there a way to activate the onQueryTextSubmit method with the voice recognizer (or something similar which doesn't require re-creating the activity?) The reason I am asking is because if the recognizer has to send an intent, I have to create and send an additional bundle with APP_DATA and that doesn't seem to be working.

So my question is:

(1) How do you use (or can you use) an onQueryTextSubmit listener with voice recognition search enabled? (the same way you would use it with regular text based search)

(2) If (1) is not possible, then how can I pass additional data with the voice recognition search query via an intent? I tried adding it through onSearchRequested() like this:

@Override
public boolean onSearchRequested() {
    Bundle appData = new Bundle();
    appData.putInt("testKey", 44);
    this.startSearch(null, true, appData, false);
    return true;
}

                    
                    
                    
Edit
Report