The search interface opens a new search action.

I am trying to use Search Manager with Android.

In fact, I have an activity I'm calling in

onSearchRequested() 

Then I use this function in the same activity to get the search string:

  // Get the intent, verify the action and get the query Intent intent = getIntent(); if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); } 

The problem is this: when I click the search button, I open a new activity, and I would like to stay on the same and do some searches. So my goal is to avoid opening a new action when I click the search button.

Thanks.

+4
source share
2 answers

The solution is to reuse the development example http://developer.android.com/guide/topics/search/search-dialog.html

It is important that 2 actions are created, one for searching and one for displaying results.

In the manifest, use this code:

 <application ... > <!-- this is the searchable activity; it performs searches --> <activity android:name=".SearchableActivity" > <intent-filter> <action android:name="android.intent.action.SEARCH" /> </intent-filter> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/> </activity> <!-- this activity enables the search dialog to initiate searches in the SearchableActivity --> <activity android:name=".OtherActivity" ... > <!-- enable the search dialog to send searches to SearchableActivity --> <meta-data android:name="android.app.default_searchable" android:value=".SearchableActivity" /> </activity> ... 

+4
source

use in manifest

 <activity android:name="BrowseItems" android:label="@string/browseitems" android:launchMode="singleTop"> <intent-filter> <action android:name="android.intent.action.SEARCH" /> </intent-filter> <meta-data android:name="android.app.searchable" android:resource="@xml/itemsearchable" /> </activity> 
0
source

Source: https://habr.com/ru/post/1414852/


All Articles