简体   繁体   English

在不同的任务中启动新的Android Activity

[英]Starting a new Android Activity in different task

This is a bit of a convoluted story: 这是一个令人费解的故事:

I have an Activity A . 我有一个Activity A
Activity A uses an intent to open a browser to do some authentication. Activity A使用意图打开浏览器进行一些身份验证。
When this is done, the web page redirects to a URL. 完成此操作后,网页将重定向到URL。 Activity B is set with an intent filter to be BROWSABLE, and the URL is such that the browser starts Activity B rather than opening a web page. Activity B设置为具有BROWSABLE的意图过滤器,并且URL使得浏览器启动Activity B而不是打开网页。

Activity B is therefore open, but as a 'child' of Chrome. 因此, Activity B是开放的,但作为Chrome的“孩子”。 In the recent apps window, I can see my original Activity A, then I can see Activity B under Chrome. 在最近的应用程序窗口中,我可以看到我原来的活动A,然后我可以看到Chrome下的Activity B

Any Activity I launch in Activity B seems to stay a child of Chrome. 我在活动B中启动的任何活动似乎都是Chrome的孩子。 I have tried using the intent flag FLAG_ACTIVITY_NEW_TASK but this doesn't seem to change anything. 我已经尝试使用意图标志FLAG_ACTIVITY_NEW_TASK但这似乎没有改变任何东西。

I would like to launch an Activity from Activity B that does not appear under Chrome, but under its own new task. 我想从活动B中启动一个活动,该活动不会出现在Chrome下,而是在其自己的新任务下。 Ideally, I would want to go back to the task that Activity A is in, but if this isn't possible a new one would suffice. 理想情况下,我想回到Activity A所在的任务,但如果不可能,那么新的就足够了。

I've realised that this can be accomplished by using the singleTask launch mode as described here: http://www.intridea.com/blog/2011/6/16/android-understanding-activity-launchmode 我已经意识到这可以通过使用如下所述的singleTask启动模式来实现: http//www.intridea.com/blog/2011/6/16/android-understanding-activity-launchmode

Essentially, I combined A and B into one activity, and set it to be a single task. 基本上,我将A和B组合成一个活动,并将其设置为单个任务。 When Chrome redirects to it, it returns to the original task rather than creating a new one as its child. 当Chrome重定向到它时,它会返回原始任务,而不是创建一个新任务作为其子项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM