开发者

Android: making search available throughout the whole application

Right now I'm adding

<intent-filter>
 <action android:name="android.intent.action.SEARCH" />
 <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable" />

to every single <activity> in 开发者_开发知识库the AndroidManifest.xml, receive the Intent in each activity and forward the search string to one singleTop activity that actually performs the search (via HTTP/JSON) and displays the results in a list.

I'm wondering if there's a way how I can set-up the AndroidManifest.xml, so that search is activated in each activity within my application, but the search string will get forwarded from Android's search box directly to my singleTop SearchResults_Activity instead of going the way through validating events in each activity and then forwarding the search string.


The answer to that is actually available in the SearchManager documentation, in the MetaData chapter.

Activities which are part of a searchable application, but don't implement search itself, require a bit of "glue" in order to cause them to invoke search using your searchable activity as their primary context. If this is not provided, then searches from these activities will use the system default search context.

<application>
    <meta-data android:name="android.app.default_searchable"
                android:value=".MySearchActivity" />

    <!-- followed by activities, providers, etc... -->
</application>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜