打开浏览器的意图,但不要把它的活动堆栈 [英] Open Browser as Intent but don't keep it on the Activity stack

查看:207
本文介绍了打开浏览器的意图,但不要把它的活动堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在与了解活动的堆栈和它是如何影响我的应用程序的行为的一些问题。

I'm having some problems with understanding the activity stack and the behaviour of how it affects my app.

一旦点击一个按钮,它开始将打开浏览器的意图。当我在浏览器和I preSS home键我降落到主屏幕。现在,如果我重新开始我的应用程序通过发射器将打开浏览器,而不是我的应用程序。我怎样才能规避启动时我的应用程序打开浏览器吗?

Upon clicking a button it starts an Intent which opens the browser. When I'm in the Browser and I press the home button I land onto the homescreen. Now if I start my app again via launcher it opens the browser instead of my app. How can I circumvent opening the browser upon launching my app?

现在,code打开一个URL看起来是这样的:

Right now, the code to open an url looks like this:

private void openUrlExternal(String url) {
    Intent openUrlIntent = new Intent(Intent.ACTION_VIEW);
    openUrlIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    openUrlIntent.setData(Uri.parse(url));
    startActivity(openUrlIntent);
}

我使用了错误的标志?那么,是什么旗做我必须使用?

Am I using the wrong flags? If so, what flags do I have to use?

在此先感谢!

推荐答案

尝试这样的:

openUrlIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
openUrlIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

这应该取消自己的浏览器中的任务,这意味着当你重新启动你应该去你的活动,而不是浏览器。

That should disassociate the browser task from your own which means when you re-launch yours it should go to your Activity instead of the browser.

不过这也取决于你在哪里调用openUrlExternal()。如果调用此当你的活动启动它仍然要带你回浏览器,但如果你从一个事件侦听器(例如按钮点击),那么当你重新启动你的应用程序不应该被调用调用它。

However it also depends on where you are calling openUrlExternal() from. If you call this when your activity launches it is still going to take you back to the browser, but if you call this from an event listener (i.e. Button click) then it shouldn't get called when you re-launch your app.

这篇关于打开浏览器的意图,但不要把它的活动堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆