I have an Android app which has a few different activities for browsing articles and images downloaded from RSS.
I'd like to be able to offer to hook up the search button to the Search dialog, using the a searchable.xml
file. I've managed to do this with one search, using:
<activity android:name=".search.SearchResultsActivity"
android:label="@string/search_results_activity_title" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable_articles"/>
</activity>
and in the <application />
<meta-data android:name="android.app.default_searchable"
android:value=".search.SearchResultsActivity" />
I can now launch the Search dialog from any activity, and it launches the SearchResultsActivity
.
I would now like to be able to search for images when the user is an ImageListActivity
, using a searchable_images.xml
, and use the default everywhere else.
I have a SearchResultsImageActivity
which includes the following meta-data element, and used the same element in the ImageListActivity
.
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable_images"/>
On pressing the search button in the ImageListActivity
, I get the default search from searchable_articles.xml
.
If I change the default_searchable
to SearchResultsImageActivity
, the image search is always launched, and the article search is never launched.
If I remove the default_searchable
meta-data element altogether, and add searchable
meta-data only selected activities, no search is launched.
I'm fairly sure this should be possible, but I don't know what I'm doing wrong.
If you override the search function in just that activity, it should prevent the search call from going up to the application level. The return value controls if the call is propagated up.
One way I did this was to create fake activities then switch out the activities when you need them.
Create two class that are named for the sub activities.
then create intents like this when component is clicked...
and call the intents from onClick when a button is clicked or some other component is click:
In your
Manifest
file update theImageListActivity
activity tagSo when you will trigger native search in
ImageListActivity
it will invoke theSearchResultsImageActivity
and default one for others.Assuming
SearchResultsImageActivity
issearchable
.