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

时间:2011-09-02 11:01:21

标签: android android-activity

我知道有很多关于这方面的讨论,但我不能让它正常工作。

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

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

这是正常的,如果我按HOME并从打孔机中选择(A) (B)被带到前面。这就是我想要的,用户可以继续使用图片,

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

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

我看不出这样做的好方法,为什么Android Gallery会恢复(A)? 也许我做错了,因为打开Android画廊带给我(A)
任何帮助将不胜感激

2 个答案:

答案 0 :(得分:0)

这可能是基于问题中有限信息的推理,假设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。

答案 1 :(得分:0)

UPDATE
我知道这是一个错综复杂的场景。在(B)发布之后,我通过简单地杀死(A)/ finish()来制定一个有效的解决方案。现在,

如果我按HOME并再次打开Android图库,我会看到Android图库 如果我按HOME并打开A我看到B.
如果我从B按回来,我会看到画廊

相关问题