在同一 Activity 中在 Android 上执行搜索

发布于 2024-11-17 13:24:05 字数 699 浏览 3 评论 0原文

我正在尝试将搜索集成到我的应用程序中,但我被一个问题阻止了。我的活动是这样声明的,位于 TabActivity 内部。

    <activity
        android:name="FileBrowserActivity"
        android:screenOrientation="portrait"
        android:launchMode="singleInstance">

        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
        <meta-data android:name="android.app.searchable"
                   android:resource="@xml/searchable"/>
    </activity>

正如你所看到的,它的 launchMode 设置为 singleTop。但是,当我调用搜索时,输入搜索查询并按 Enter 键,会启动此类活动的另一个实例。没有调用 onNewIntent!但在启动的活动中,每个新搜索不会启动新活动。

期望的行为是保持在当前活动范围内。基本上这就是 android 启动器搜索的工作原理。

I'm trying to integrate search in my app but I'm being blocked by one issue. My activity is declared like this and is located inside of TabActivity.

    <activity
        android:name="FileBrowserActivity"
        android:screenOrientation="portrait"
        android:launchMode="singleInstance">

        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
        <meta-data android:name="android.app.searchable"
                   android:resource="@xml/searchable"/>
    </activity>

As you can see its launchMode is set to singleTop. But when I invoke search, input the search query and press enter another instance of such activity is launched. No onNewIntent is being called! But in the launched activity each new search doesn't launch a new activity.

The desired behaviour is to stay within current activity. Basically that's how android launcher search works.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

您应该使用 android:launchMode="singleTop" 就像所描述的 在本文中

You should rather use android:launchMode="singleTop" like described in this article.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文