Android Browser: open several URLs, each on new window/tab (programmatically)
Asked Answered
G

2

2

I know how to open a URL using Intents:

Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.lala.com"));
startActivity(browserIntent);

But how can I open multiple URLs, each on new window/tab???

Tried creating several Intents and opened each with different startActivity but it just opens the last one on the list;

code code code
startActivity(Intent1); startActivity(Intent2); startActivity(Intent3); -> only Intent3 is opened eventually (which of course make sense :)).

Appreciate any help!

UPDATE: still looking for an answer :/

I've come up with a possible solution, which indeed opens the URL in a new window.

Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.go.com"));
Bundle b = new Bundle();
b.putBoolean("new_window", true); //sets new window
intent.putExtras(b);
startActivity(intent);

BrowserBookmarksPage.java

Any way of somehow start the Activity to open several URLs at once? something with setResult() & startActivityForResult() maybe?

Glassware answered 7/11, 2010 at 18:38 Comment(8)
@liorry: Write your own browser using WebView. Or, think about usability and abandon your plan.Cary
Can't use my own browser :\ so you mean it's totally impossible?Glassware
Since WebView does everything for you, it wouldn't be that hard to do. But I confess I'm wondering whether 3 web-pages popping open all at once could ever be a good user experience.Welltimed
@Reuben, can you show an example? I want to open the URLs in the default system Browser.Glassware
Btw, regarding usability, I find it very weird I can't open multiple websites in one click by default. Android Browser closes the Bookmarks window every time I open only one bookmark, even if it's set to open in a new window in the background.Glassware
I meant that writing your own browser wouldn't be that hard to do. Not sure it's ever a good idea for apps to open multiple browser windows, far too much potential for spammy abuse. Why not describe the problem you are solving in a little more detail? Am sure there's a better way.Welltimed
@Reuben: Thanks for replying. I know writing my own browser isn't that hard but it's not were I intend my app. I'm writing a Bookmarks manager with some extra features. one of them is to allow the user to delete multiple bookmarks in one click. the other I wanted is to allow the user to open multiple bookmarks in one click - I know I miss it on my everyday use, so I guess others miss it too. it's not for spam or something :)Glassware
Updated my answer with a partial solution. would appreciate any advice how to use it to open multiple Intents (or putExtras on the sameone) when I start the Activity.Glassware
G
6

I've come up with a possible solution, which indeed opens the URL in a new window.

Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.go.com"));
Bundle b = new Bundle();
b.putBoolean("new_window", true); //sets new window
intent.putExtras(b);
startActivity(intent);
Glassware answered 8/11, 2010 at 19:22 Comment(0)
S
4

According to this

The second attack vector exploits the interval of time the Android browser needs to process intents properly. If two intents are sent in a short enough interval of time, the browser will execute them in the same tab. The first intent can be to open the targeted domain and the second can be to execute rogue javascript.

So to answer your question, put a small delay in between 2 startActivity.

Stirk answered 20/3, 2012 at 16:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.