我有一个活动处理搜索(ACTIVITY_1),当我在此活动内/从此活动使用搜索(通过手机上的SEARCH按钮)时,它可以正常工作.
但是,当我通过实现onNewIntent从另一个活动(ACTIVITY_2..x)使用搜索并将查询字符串转发到我的Search_Activity.class(ACTIVITY_1)时
@OverrIDeprotected voID onNewIntent(Intent intent) { Log.i(TAG, "onNewIntent()"); if (Intent.ACTION_SEARCH.equals(intent.getAction())) { Log.i(TAG, "===== Intent: ACTION_SEARCH ====="); Intent myIntent = new Intent(getBaseContext(), Search_Activity.class); myIntent.setAction(Intent.ACTION_SEARCH); myIntent.putExtra(SearchManager.query, intent.getStringExtra(SearchManager.query)); startActivity(myIntent); }}
它总是首先暂停ACTIVITY_2,然后转到ACTIVITY_2的onCreate().
>为什么它已经存在并且不直接进入onNewIntent时重新创建我的ACTIVITY_2?
>还有其他方法可以将搜索查询直接转发到ACTIVITY_1吗?例如,通过Manifest.xml中的设置
>是否可以自动将所有搜索查询自动转发到ACTIVITY_1,甚至不在所有其他活动中实施onNewIntent?
目前我必须放一个< intent-filter>在每个单独的活动中“激活”我的自定义搜索并将查询转发到通过onNewIntent处理搜索的活动(如上所示).
<activity androID:name=".Another_Activity" androID:theme="@style/Mytheme"> <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>
解决方法:
我不确定我是否了解您所描述的事件链,但是在这种情况下,您需要如何配置应用程序ACTIVITY_1是您在用户按下“搜索”时始终要从所有其他活动启动的搜索活动按钮.
假设搜索按钮在Activity1上完美运行,您只需向应用程序添加一些粘合元数据,告诉它您的所有其他活动应使用ACTIVITY_1进行搜索,如下面的清单代码段所示:
<application> <Meta-data androID:name="androID.app.default_searchable" androID:value=".ACTIVITY_1" /> <!-- All your activitIEs, service, etc. --></application>
使用此方法,您应该能够从除ACTIVITY_1之外的所有 *** 作中删除intent-filters,并且您不需要在任何其他活动中使用onNewIntent处理程序.
总结以上是内存溢出为你收集整理的Android:将搜索查询转发到处理搜索的单个活动全部内容,希望文章能够帮你解决Android:将搜索查询转发到处理搜索的单个活动所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)