I am successfully using a search widget in my action bar to perform a search following this guide. The search is fine, but I'm wondering how to pass additional variables on a search. The same guide states I can override onSearchRequested(), but this doesn't seem to work with a search widget.
Override in question:
@Override public boolean onSearchRequested() { Bundle appData = new Bundle(); appData.putString("KEY", "VALUE"); startSearch(null, false, appData, false); return true; }Getting the bundle in my activity class:
protected void onCreate(Bundle savedInstanceState) { // ... Intent intent = getIntent(); Bundle appData = intent.getBundleExtra(SearchManager.APP_DATA); String value = appData.getString("KEY"); Log.d("VALUE", value); // ... }
My application crashes upon creating the search class because appData is always null.
Note
onSearchRequested() is called, but the bundle does not make it to my onCreate() method.
All extras from the passed intent are {user_query=my-query, query=my-query}.