如何从 singleInstance 活动启动活动?

发布于 2024-11-03 18:42:16 字数 1013 浏览 2 评论 0原文

我有一个小部件,单击时可以弹出小对话框。这些对话框由名为 RemoteActivity 的活动以 singleInstance launchMode 显示。在其中一个对话框中,有一个按钮用于启动主应用程序 MainActivity,它具有标准的 launchMode。

但是,当单击此按钮并调用 startActivity() 时,尽管我可以在 logcat 中看到相应的“正在启动活动:Intent { ... }”,但 MainActivity 并未启动。

如果我将 RemoteActivity 的 launchMode 设置为标准,那么 MainActivity 就会启动,但这不是我想要的,RemoteActivity 只是小部件的扩展,我不希望它与任何其他活动堆栈。

我也尝试过 FLAG_ACTIVITY_NEW_TASK 但它没有帮助,而且无论如何也没有必要 根据文档

“singleInstance”活动,在 另一方面,不允许其他 活动作为其任务的一部分。 这是任务中唯一的活动。如果 它开始另一个活动,即 活动被分配给不同的 任务 — 就像 FLAG_ACTIVITY_NEW_TASK 是在意图中。

我如何启动我的主要活动?

更新/勘误:

MainActivity 实际上已启动,但前提是它还不是任务的一部分。如果我通过启动器正常启动 MainActivity,然后按“返回”退出,则 RemoteActivity 会启动 MainActivity。

但是,如果我不按 Back,而是按 Home 离开 MainActivity,则 RemoteActivity 无法启动 MainActivity,尽管意图出现在 logcat 中。

我正在 Froyo 上测试这个。

知道发生了什么吗?

I have a widget which can pop up small dialogs when clicked. These dialogs are displayed by an activity called RemoteActivity in singleInstance launchMode. In one of these dialogs, there is a button to launch the main app MainActivity, which has the standard launchMode.

However, when this button is clicked, and startActivity() called, MainActivity isn't launched, although I can see the corresponding "Starting activity: Intent { ... }" in logcat.

If I set the launchMode of RemoteActivity to standard then MainActivity gets launched, but this isn't what I want, RemoteActivity is merely an extension of the widget, I don't want it to stack with any other activity.

I also tried with FLAG_ACTIVITY_NEW_TASK but it didn't help, and it shouldn't be necessary anyway according to the docs:

A "singleInstance" activity, on the
other hand, permits no other
activities to be part of its task.
It's the only activity in the task. If
it starts another activity, that
activity is assigned to a different
task — as if FLAG_ACTIVITY_NEW_TASK
was in the intent.

How can I launch my main activity?

UPDATE / ERRATA:

The MainActivity is actually launched but only if it isn't already part of a task. If I launch MainActivity normally through the launcher, and press Back to exit, then RemoteActivity does launch MainActivity.

But if, instead of pressing Back, I press Home to leave MainActivity, then RemoteActivity can't launch MainActivity, although the intent appears in logcat.

I'm testing this on Froyo.

Any idea of what's happening?

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

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

发布评论

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

评论(2

紫南 2024-11-10 18:42:16

也许 noHistory 标志 适合您正在寻找的内容为了?

Maybe the noHistory flag will work for what you are looking for?

聽兲甴掵 2024-11-10 18:42:16

我发现问题:只有在 RemoteActivity 中的 startActivity() 之前调用 finish() 时,才会出现此行为。如果我在 finish() 之前调用 startActivity() ,那么无论 MainActivity 是否已经是现有任务的一部分,它都可以正常工作。

去算算...

I found the problem: this behavior only occurs when calling finish() before startActivity() in RemoteActivity. If I call startActivity() before finish() then it works fine whether MainActivity is already part of an existing task or not.

Go figure...

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