Starting a new Android Activity in different task

2019-05-16 02:09发布

This is a bit of a convoluted story:

I have an Activity A.
Activity A uses an intent to open a browser to do some authentication.
When this is done, the web page redirects to a 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 is therefore open, but as a 'child' of Chrome. In the recent apps window, I can see my original Activity A, then I can see Activity B under Chrome.

Any Activity I launch in Activity B seems to stay a child of Chrome. I have tried using the intent flag FLAG_ACTIVITY_NEW_TASK but this doesn't seem to change anything.

I would like to launch an Activity from Activity B that does not appear under Chrome, but under its own new task. 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.

1条回答
【Aperson】
2楼-- · 2019-05-16 02:26

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

Essentially, I combined A and B into one activity, and set it to be a single task. When Chrome redirects to it, it returns to the original task rather than creating a new one as its child.

查看更多
登录 后发表回答