安卓onSearchRequested()回调到调用活动 [英] Android onSearchRequested() callback to the calling activity

查看:451
本文介绍了安卓onSearchRequested()回调到调用活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MapActivity将显示Android的搜索框,当一个搜索按钮pssed $ P $。该SearchManager管理对话框,并将用户的查询到一个可搜索的活动,它搜索一个SQLite数据库,并使用自定义适配器显示结果。

I have a MapActivity that will display the Android Search box when a search button is pressed. The SearchManager manages the dialog, and passes the user's query to a searchable activity, which searches an SQLite DB and displays the results using a custom adapter.

这工作得很好 - 和我越来越从数据库中正确的结果显示

This works fine - and I'm getting the correct results from the DB displayed.

不过,我想要做的是,当用户点击一个搜索结果在地图上的MapActivity显示结果。目前,这意味着开始新MapActivity,通过在搜索结果中使用的是捆绑。

However, what I want to do is display the result in the MapActivity on a map when the user clicks on a search result. Currently, this means starting a new MapActivity, passing the search result in using a Bundle.

我还以为清洁方法是通过搜索结果返回给原来的活动,而不是开始一个新的。此刻,我的活动栈云MapAct - > SearchManager - >搜索结果 - >新建MapAct。这意味着来自新MapAct pressing后将返回到查询结果,然后向原始MapAct

I'd have thought the cleaner way was to pass the search result back to the original activity, rather than start a new one. At the moment, my activity stack goes MapAct -> SearchManager -> Search Result -> New MapAct. Which means pressing "back" from the new MapAct will go back to the query results, then to the original MapAct.

看来,在搜索结果中,称光洁度()不会导致onActivityResult被称为在调用MapActivity。

It seems that in the Search Result, calling finish() does not cause onActivityResult to be called in the calling MapActivity.

任何想法如何得到这个回调,保持合理的活动栈?

Any ideas how to get this callback and maintain a sensible activity stack?

推荐答案

我一直在周围挖了回答这个问题询问,终于找到一些作品。我不得不做出原始调用活动的的可搜索的活动,所以我在清单条目是这样的:

I've been digging around for an answer to this exact question and finally found something that works. I had to make the original calling activity also the searchable activity, so my entry in the manifest looks like this:

<activity android:name=".BaseActivity"
          android:launchMode="singleTop">
   <!-- BaseActivity is also the searchable activity -->
   <intent-filter>
      <action android:name="android.intent.action.SEARCH" />
   </intent-filter>
   <meta-data android:name="android.app.searchable"
              android:resource="@xml/searchable"/>
   <!-- enable the base activity to send searches to itself -->
   <meta-data android:name="android.app.default_searchable"
              android:value=".BaseActivity" />
</activity>

然后,而不是搜索在这个活动中,手动 startActivityForResult 与真正的搜索活动,这将允许您为的setResult 完成返回到原来的调用活动。

And then instead of searching in this activity, manually startActivityForResult with the real search activity, which will then allow you to setResult and finish back to the original calling activity.

我走进了<一个更详细一点href="http://blog.dpdearing.com/2011/05/getting-android-to-call-onactivityresult-after-onsearchrequested/"相对=nofollow>此处博客文章。

这篇关于安卓onSearchRequested()回调到调用活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆