如何通过已经运行的Activity切换到正在运行的Activity

发布于 2024-12-03 04:16:21 字数 613 浏览 0 评论 0原文

我知道有很多关于此的讨论,但我无法使其正常工作。

Activity (A) = singleTop 并且可以接收 android.intent.action.SEND
Activity (B) = singleTask

当我从 Android 图库中选择一张图片并使用 (A) 打开它
(A) 将意图重定向到 (B)。

这工作正常,如果我按 HOME 并从午餐器中选择 (A) (B) 被带到前面。这就是我想要的,用户可以继续查看图片,

现在,如果我按 HOME 并再次打开 Android Gallery,则 (A) 是
onRestart()OnStart()onResume()。我看到了(A)。

这是我喜欢切换到(B)的问题,因为用户需要完成他正在做的事情。

我看不出有什么好方法来做到这一点,为什么 Android Gallery 会恢复 (A)?
自从打开 Android Gallery 给我带来的可能是我做错了什么 (A)
任何帮助将不胜感激

I know there are much discussions about this but i cannot get this to work properly.

Activity (A) = singleTop and can receive android.intent.action.SEND
Activity (B) = singleTask

When i from the Android Gallery select a picture and open it with (A)
The (A) is redirecting the intent to (B).

This is working ok and if i press HOME and select (A) from the luncher
the (B) is brought to front. That is what i want and user can continue with picture,

Now, if i press HOME and open the Android Gallery again the (A) is
onRestart(), OnStart() and onResume(). and i see (A).

This is the problem i like to switch to (B) because user need to finish what he was doing.

I cannot see a good way to do that and why does the Android Gallery resume (A)?
Maybe i do something wrong since opening the Android Gallery bring me (A)
Any help would be appreciated

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

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

发布评论

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

评论(2

生活了然无味 2024-12-10 04:16:21

这是基于问题中有限信息的可能推理,假设 A 在其 onCreate() 中将意图重定向到 B。

1) 打开图库,选择一张图片,用 A 打开,将其重定向到 B

Task1 has stack has Gallery, A, B (B on top of the stack)

2) 按 home,从启动器中选择 A

Launcher app creates a new task, new task2's stack has a new instance of activity A, its onCreate() is invoked and intent is redirected to B. B being a singleTask is moved from Task1 to Task2 and its onNewIntent() would be invoked.

3) 按 home,然后打开图库

Task1 is resumed and the top of the stack is now A. Its onRestart(), onStart() and onResume() is invoked.

在这种情况下,您可以尝试从 A 的 onStart() 重定向意图或者没有 B 作为 singleTask。

This is possible reasoning based on limited info in the question, assuming A is redirecting the intent to B in its onCreate().

1) Open Gallery, select a picture, open with A, redirect it to B

Task1 has stack has Gallery, A, B (B on top of the stack)

2) Press home, select A from launcher

Launcher app creates a new task, new task2's stack has a new instance of activity A, its onCreate() is invoked and intent is redirected to B. B being a singleTask is moved from Task1 to Task2 and its onNewIntent() would be invoked.

3) Press home, and open gallery

Task1 is resumed and the top of the stack is now A. Its onRestart(), onStart() and onResume() is invoked.

This being the scenario, you can try redirecting the intent from A's onStart() or do not have B as singleTask.

百变从容 2024-12-10 04:16:21

更新
我知道这是一个复杂的场景。我通过在 (B) 启动后简单地杀死 (A)/finish() 来制定一个可行的解决方案。现在,

如果我按 HOME 并再次打开 Android Gallery,我会看到 Android Gallery。
如果我按 HOME 并打开 A,我会看到 B。
如果我从 BI 回复,请查看画廊

UPDATE
I know this is an intricate scenario. I have made a working solution by simply killing (A)/finish() after the launch of (B). Now,

if i press HOME and open the Android Gallery again i see Android Gallery.
if i press HOME and open A i see B.
if i press back from B I see the gallery

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