I am using a SearchView for starting a new activity that shows the search results. I have followed the following sources:
- Android tutorial: Creating a Search Interface
- SO: Start new activity from SearchView
- SO: Cannot get searchview in actionbar to work
The new searchable activity ListActivity
is launched from a SearchView widget inside the App Bar in MainActivity
. The new searchable activity is started but the search intent is missing (onNewIntent
method is never called).
Searchable.xml
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_label"
android:hint="@string/search_hint" >
</searchable>
AndroidManifest.xml
<application
...
<meta-data
android:name="android.app.default_searchable"
android:value=".ui.ListActivity" />
<activity
android:name=".ui.MainActivity"
...
</activity>
<activity
android:name=".ui.ListActivity"
android:launchMode="singleTop"
...
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
</activity>
</application>
MainActivity
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// setSupportActionBar
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setSearchableInfo( searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false);
return true;
}
}
ListActivity
public class ListActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate invoked"); //Log Printed
...
}
@Override
protected void onNewIntent(Intent intent) {
Log.d(TAG, "onNewIntent invoked"); //Log NOT Printed
}
}
Consider that I have also replaced getComponentName()
with new ComponentName(this, ListActivity.class)
but got the same result: no errors, no intent query.