2016-08-22 60 views
0

我想从我的应用程序打开网址,以显示在浏览器中,但我想这样做,用户不需要点击“返回”去我的应用程序,并可以使用多任务按钮。所以我的应用程序的活动堆栈保持独立于浏览器。有没有办法在android中使用新的活动堆栈打开URL?

有什么办法可以达到这个目的吗?

回答

1

你可以试试这个!

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.stackoverflow.com")); 
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) 
startActivity(intent); 
0
Try this: 

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); 
startActivity(browserIntent); 

That works fine for me. 
As for the missing "http://" I'd just do something like this: 
if (!url.startsWith("http://") && !url.startsWith("https://")) 
url = "http://" + url; 
+0

这似乎并不能解决活动堆栈问题。 – Punga

+0

'intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)'? – CodeWalker

+0

@CodeWalker谢谢!这样做了,你可以将它作为单独的答案张贴,所以我可以检查它是正确的吗? – Punga

相关问题