为什么我的可搜索活动的Intent.getAction()为null?

时间:2010-04-25 13:34:28

标签: android search action android-intent

我已经按照SearchManager文档进行操作,但仍然无法搜索我的某个应用活动。从我的活动中,出现搜索对话框,我输入查询,点击搜索,我的活动重新打开,然后我在日志中看到这一点:

D/SearchDialog(  584): launching Intent { act=android.intent.action.SEARCH flg=0x10000000 cmp=com.clinkybot.geodroid2/.views.Waypoints (has extras) }
I/SearchDialog(  584): Starting (as ourselves) #Intent;action=android.intent.action.SEARCH;launchFlags=0x10000000;component=com.clinkybot.geodroid2/.views.Waypoints;S.user_query=sdaf;S.query=sdaf;end
I/ActivityManager(  584): Starting activity: Intent { act=android.intent.action.SEARCH flg=0x10000000 cmp=com.clinkybot.geodroid2/.views.Waypoints (has extras) }
D/WAYPOINTS( 1018): NI Intent { cmp=com.clinkybot.geodroid2/.views.Waypoints (has extras) }
D/WAYPOINTS( 1018): NI null
D/WAYPOINTS( 1018): NI false 

在我看来,在最后三行之前一切都很好。 “NI”行分别为getIntent().toString(), getIntent().getAction()getIntent().hasExtra(SearchManager.QUERY)

ActivityManager似乎正在以正确的操作开始我的活动。然后当我的活动开始时,它不包含任何动作!?我做错了什么?

我的清单的相关部分是:

<activity android:name=".views.Waypoints" android:label="Waypoints" android:launchMode="singleTop">
   <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" />
  </activity>

1 个答案:

答案 0 :(得分:16)

这花了我太多时间。从可搜索的singleTop活动(在我的案例中为Waypoints)中执行搜索时,您必须覆盖onNewIntent()并在那里获取搜索查询。几个小时之后,我在做什么。问题是getIntent()不返回用于调用活动的Intent(head explodes)。在我执行第一次搜索之前,它似乎返回了打开我可搜索活动的原始Intent。

onNewIntent method收到搜索意图。我用onNewIntent()中的param替换了getIntent()和boom,progress。

虽然我必须承认;搞清楚这样可以减轻无法逃避与星共舞在背景中咆哮的声音的挫败感。

相关问题