如何使用Android的搜索查看无singleTop? [英] How to use an Android SearchView without singleTop?

查看:121
本文介绍了如何使用Android的搜索查看无singleTop?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我通常要存在于多个任务,从而使返回按钮恢复一个previous状态的活动;不过,我也想用一个搜索查看与现有的活动,而不力推新入任务堆栈(因为我要搜索什么当前显示'S)。这里是我的问题:

I have an activity that I normally want to exist in multiple tasks, so that the [Back] button restores a previous state; however, I also want to use a SearchView with an existing activity, without pushing a new one onto the task stack (since I want to search what's currently displayed). Here's my problem:

  • 如果我设置了活动的启动模式为singleTop,则搜索查看适用于当前的活动,但<一个href="http://developer.android.com/reference/android/content/Context.html#startActivity(android.content.Intent)"相对=nofollow> Context.startActivity 不增加新的活动到堆栈中。
  • 如果我设置了活动的启动模式为标准, startActivity 的增加​​了新的活动到堆栈,但搜索查看也创造而不是搜索现有的一个新的(空)的活动。
  • If I set the activity's launch mode to "singleTop", the SearchView works with the current activity, but Context.startActivity does not add new activities to the stack.
  • If I set the activity's launch mode to "standard", startActivity adds new activities to the stack, but SearchView also creates a new (empty) activity, instead of searching the existing one.

我找不到任何办法让搜索查看使用意向的标志(如 FLAG_ACTIVITY_SINGLE_TOP 。我试着去周围的其他方法,设置启动模式为singleTop,然后添加的 FLAG_ACTIVITY_NEW_TASK 每一个意图,但这只是从不同的活动课开展工作的时候;当我尝试从自己的类发起活动的新实例,Android的不尊重FLAG_ACTIVITY_NEW_TASK和没有推新任务压入堆栈。

I can't find any way make SearchView use intent flags (e.g. FLAG_ACTIVITY_SINGLE_TOP. I tried going the other way around, setting launch mode to "singleTop" then adding FLAG_ACTIVITY_NEW_TASK to every intent, but that worked only when launching from a different activity class; when I try to launch a new instance of an activity from its own class, Android didn't respect FLAG_ACTIVITY_NEW_TASK and didn't push a new task onto the stack.

也许有什么东西我可以在<一做href="http://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent)"相对=nofollow> Activity.onNewIntent 强制活动克隆自己呢。

Perhaps there's something I can do in Activity.onNewIntent to force the activity to clone itself then.

我就放弃了搜索查看,只是写我自己的自定义插件的边缘,尽管事实上的开始的Andr​​oid 3.0,使用搜索查看小部件的操作栏中的项目是preferred方式提供在应用程序搜索的(来源) - 到目前为止,它是在不平凡的情况下非常有用,似乎太不灵活,不可配置

I'm on the verge of giving up on SearchView and just writing my own custom widget, despite that fact that "Beginning in Android 3.0, using the SearchView widget as an item in the action bar is the preferred way to provide search in your app" (Source) — so far, it seems just too inflexible and non-configurable to be useful in non-trivial cases.

有没有人找到了解决这个问题呢?

Has anyone found a solution to this problem?

推荐答案

很多反思和错误的开始后,我意识到,搜索查看只是错误的事情完成这个任务。谷歌设计的搜索查看与搜索活动的一记非常特殊:

After a lot of reflection and false starts, I realized that SearchView was simply the wrong thing for this task. Google designed SearchView with a very specific type of search activity in mind:

  • 在搜索查询的用户类型。
  • 在该应用程序推出结果列表一个新的活动。

这不是我所用的搜索模式;相反,我想用细化查询,屏幕上当前显示的列表 - 它更是一个过滤的搜索比同步查询和响应模型。搜索查看是不是为这一点,所以我继续写我自己的小工具(和其绑定到搜索菜单项和搜索按钮)。

That's not the search model I was using; instead, I wanted to refine a list currently shown on the screen using the query — it was more of a filtering search than a synchronous query and response model. SearchView is not designed for that, so I went ahead and wrote my own widget (and bound it to the search menu item and the search button).

我很惊讶,没有人对这个问题有任何意见 - 通常是Android的问题,产生了大量的讨论。我想,这是刚刚出过远那里。

I'm surprised that no one had any comments on this question — usually Android questions generate a lot of discussion. I guess that this was was just too far out there.

这篇关于如何使用Android的搜索查看无singleTop?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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