我怎样才能做到这在Android中。活动 - > web浏览器 - > Acrivity,但preSS回到看不到web浏览器浏览器、这在、Android、web

2023-09-06 03:27:00 作者:夜袭尼姑庵

我如何能做到这一点的网络浏览器调用自定义方案启动的活动的话,我想我preSS后退按钮,但不会返回Web浏览器。

How can I do that the web browser call a custom scheme to start a activity, then I want I press the Back Button but not return the web browser.

我只是想实现转发当我打电话web浏览器,然后打电话给我的计划,以启动另一个活动。当我回来了,我不会喜欢看到的网页浏览器。

I just want to implement forwarding when I call a web browser then call my scheme to start another Activity. When I back, I will not like to see the web browser.

我应该怎么办呢?

Intent i = new Intent(Intent.ACTION_VIEW);
i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
i.setData(Uri.parse(url));
startActivity(i);

我已经加入,但它不工作!

I already added it, but it not works!

推荐答案

此可能是因为第二活动发射到从启动浏览器相同的任务,这意味着开始的第二个活动返回到与已经存在的任务最上面的活性(活性1)被推到后端堆栈。请参见这里。

This probably happens because the second activity is launched into the same task you started the browser from, which means that starting your second activity returns to the already existing task with the topmost activity (activity 1) pushed to the back-stack. See here.

如果你让你的第二个活动正在启动一个不同的任务,pressing回应该结束了任务,并返回到该任务后,浏览器。

If you make your second activity being started on a different task, pressing "back" should end that task and return to the task behind, the browser.

要实现这个目标,你可以使用 FLAG_ACTIVITY_NEW_TASK 的意图开始活动2,或设置活动的安卓launchMode 属性 singleTop 在你的清单。

To accomplish that, you could use FLAG_ACTIVITY_NEW_TASK in the intent starting activity 2, or set the activity's android:launchMode attribute to singleTop in your manifest.