我已经关注了SearchManager文档,但仍然无法使我的某个应用的活动搜索到。从我的活动,出现在搜索对话框,我输入查询,点击搜索,我的活动重新打开,然后我看到这个在日志中:为什么我的可搜索活动的Intent.getAction()为空?
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>
我很高兴在我的头部爆炸之前发现了这个SO问题。这在应用基础知识指南中提到,但该死的在[Intent#FLAG_ACTIVITY_SINGLE_TOP](http://j.mp/gkTnyw)中提及onNewIntent而不是仅在[Intent#FLAG_ACTIVITY_CLEAR_TOP](http:///j.mp/fNlEM3)。此外,[Activity#getIntent](http://j.mp/ftcS6p)的文档甚至没有提及任何东西!呃... 那就说,谢谢。 – brack 2011-01-07 18:51:46
所以也许最好总是从onCreate调用onNewIntent(getIntent()),只是让你知道它遵循相同的代码路径。 – mclin 2011-01-26 22:22:16
你的问题在这里解释http://developer.android.com/guide/topics/search/search-dialog.html#LifeCycle,但是即使应用这个,我仍然得到空... – max4ever 2012-06-01 10:56:13