为什么我的可搜索活动的 Intent.getAction() 为空? [英] Why is my searchable activity's Intent.getAction() null?

查看:24
本文介绍了为什么我的可搜索活动的 Intent.getAction() 为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照 SearchManager 文档进行操作,但仍然遇到问题使我的应用程序的一项活动可搜索.从我的活动中,搜索对话框出现,我输入一个查询,点击搜索,我的活动重新打开,然后我在日志中看到:

I've followed the SearchManager documentation yet am still having trouble making one of my app's activities searchable. From my activity, the Search dialog appears, I enter a query, hit search, my activity reopens, then I see this in the log:

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).

It appears to me that everything is fine up until the last three lines. The "NI" lines are getIntent().toString(), getIntent().getAction(), and getIntent().hasExtra(SearchManager.QUERY) respectively.

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

ActivityManager appears to be starting my activity with the correct action. Then when my activity starts, it contains no action!? What am I doing wrong?

我的清单的相关部分是:

The relevant portion of my manifest is:

<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>

推荐答案

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

That took too many hours of my life. When performing a search from the searchable singleTop activity (in my case Waypoints) you must override onNewIntent() and grab the search query there. Which after a few hours in, I was doing. The catch was that getIntent() does not return the Intent used to call the activity (head explodes). It seems to return the original Intent that opened my searchable activity before I performed my first search.

onNewIntent 方法接收搜索意图.我将 getIntent() 替换为 onNewIntent() 和 boom, progress 中的参数.

The onNewIntent method receives the search intent. I replaced getIntent() with the param from onNewIntent() and boom, progress.

虽然我必须承认;弄清楚这一点可以减轻无法摆脱背景中与星共舞的轰鸣声的挫败感.

Though I must admit; figuring this out eases the frustration of being unable to escape the sound of Dancing with the Stars blaring in the background.

这篇关于为什么我的可搜索活动的 Intent.getAction() 为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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