如何强制浏览器不再每次打开新页面?
我想提前感谢所有花时间阅读我的帖子的人(也许会回答它:p)
我正在开发一个非常简单的 Android 应用程序,其目的是显示一个网站。 当然,我已经阅读了文档,并且我使用以下代码来显示页面:
Uri uriUrl = Uri.parse("http://example.com");
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
该网站正确显示,我在天堂:) 但.. 如果我通过按“主页”按钮退出应用程序(我知道它并没有真正退出,而是神经元)并再次启动它,网络浏览器将打开一个包含我的页面的新选项卡。我希望浏览器不创建新选项卡,而是保留第一次启动时创建的选项卡。
我不想使用 Webview,因为它意味着更多的代码,而且我想要一个非常简单的应用程序。
我是 Android 开发新手,所以请善待我:D 我对错误表示歉意,我知道我的英语很糟糕。
谢谢你们!
I'd like to thank in advance all the people who will take the time to read my post (and maybe answer it :p)
I'm developping a very simple Android application, which aims at displaying a website.
Of course, I've read the documentation, and I'm using the following code to display the page :
Uri uriUrl = Uri.parse("http://example.com");
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
The site is correctly displaying, I'm on heaven :)
But..
If i quit the application by pressing the HOME button (I know it doesn't really quit, but nervermind) and launches it again, the web browser opens a new tab containing my page. What I would like is the browser not creating a new tab, but keep the one that was created during first launch.
I'd rather not use Webviews since it implies more code, and I want a very simple application.
I'm new to Android development, so please be kind with me :D
I apologize for the errors, I know my English is bad.
Thank you guys !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对 android 开发也相当陌生,但根据我的理解,当你按你现在的方式调用浏览器时,你只是在默认浏览器中打开 URL。使用 WebView 是理想的选择,因为它特定于您的应用程序(隔离,或者至少这是我的印象)。使用网络视图并不是非常困难。下面是一些应该可以帮助您顺利进行的代码:
I'm fairly new to android dev too but from what I understand when you're calling the browser the way you are, you're just opening the URL in the default browser. Using a WebView is ideal because it is then specific to your application (isolated, or at least this is the impression I am under). Using a webview isn't incredibly difficult. Here's some code that should have you well under-way:
我一直在处理 WebView,它们完成了这项工作:) 对于 Android 开发新手来说,设置它们有点棘手,但它们非常可配置,因此可以适应所有情况。
所以我的问题的答案可能是:使用WEBVIEW!
你的代码对 Ascension 有很大帮助,它让我不必从头开始,并看到了拥有功能性 WebView 所需的一些“核心”方法。
给您的小提示:您在此处使用的一些方法在文档中被标记为“已弃用”(例如,我正在考虑 setPluginsEnabled() )。
最后但并非最不重要的一点是,对于那些想知道的人:如果您使用 Ascension 示例代码,您会注意到您的页面在每次屏幕旋转时都会重新加载。弄清楚为什么会发生这种情况对我来说有点痛苦,但这很正常,请参阅 http://www.devdiv.com/android/docs/guide/topics/resources/runtime-changes.html
I've been dealing with WebViews, and they do the work :) It's a bit tricky to set them up when new to Android development, but they are very configurable, and so can be adapted to all situations.
So the answer to my question could be : USE WEBVIEW !
Your code was a big help Ascension, it allowed me not to start from scratch and to see some "core" methods required to have a functionnal WebView.
Small note for you : some methods you use here are noted as "Deprecated" on the documentation (I'm thinking of setPluginsEnabled() for instance).
Last but not least, for those who wonder : if you take Ascension sample code, you'll notice that your page is reloaded on every screen rotation. This was a little pain for me to figure out why this happened, but it's normal, see http://www.devdiv.com/android/docs/guide/topics/resources/runtime-changes.html