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

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

问题描述

我已经试过了 SearchManager 文件尚未我仍然有让我的应用程序的一波未平活动搜索。从我的活动,出现在搜索对话框,我输入查询,点击搜索,我的活动再开,然后我看到这在日志中:

  D / SearchDialog(584):启动意向书{行动= android.intent.action.SEARCH FLG = 0x10000000处CMP = com.clinkybot.geodroid2 / .views.Waypoints(有额外) }
I / SearchDialog(584):启动(为自己) #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):启动活动:意向{行为= android.intent.action.SEARCH FLG = 0x10000000处CMP = com.clinkybot.geodroid2 / .views.Waypoints(有群众演员)}
D /航点(1018):NI意向{CMP = com.clinkybot.geodroid2 / .views.Waypoints(有群众演员)}
D /航点(1018):NI空
D /航点(1018):NI假
 

在我看来一切都很好,直到最后三行。而NI行是 getIntent()。toString()方法,getIntent()的getAction() getIntent()。hasExtra(SearchManager。查询)分别。

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

我的清单的相关部分是:

 <活动机器人:views.Waypoints名称=机器人:标签=航点的Andr​​oid版本:launchMode =singleTop>
   <意向滤光器>
    <作用机器人:名称=android.intent.action.SEARCH/>
    <类机器人:名称=android.intent.category.DEFAULT/>
   &所述; /意图滤光器>
   <元数据的android:NAME =android.app.searchable
    机器人:资源=@ XML /搜索/>
  < /活性GT;
 

解决方案

这是花了太多的时间我的生活。当执行从搜索singleTop活动搜索(在我的情况下,航点)必须覆盖onNewIntent()并获取搜索查询那里。几个小时,我所做的一切之后。美中不足的是,getIntent()不返回用于调用活动(头爆炸)的意图。这似乎返回打开了我的搜索活动之前,我进行的原意我第一次的搜索的。

的<一个href="http://developer.android.com/reference/android/app/Activity.html#onNewIntent%28android.content.Intent%29">onNewIntent法接收搜索意图。我换成getIntent()从onNewIntent的参数()和繁荣,进步。

尽管我必须承认;搞清楚了这一点简化了暂时无法逃脱的跳舞的声音与星的高音在后台的无奈。

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 

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

解决方案

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.

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天全站免登陆