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?

Lior Iluz
  • 26,213
  • 16
  • 65
  • 114
  • @liorry: Write your own browser using `WebView`. Or, think about usability and abandon your plan. – CommonsWare Nov 07 '10 at 19:51
  • Can't use my own browser :\ so you mean it's totally impossible? – Lior Iluz Nov 07 '10 at 19:54
  • 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. – Reuben Scratton Nov 07 '10 at 22:37
  • @Reuben, can you show an example? I want to open the URLs in the default system Browser. – Lior Iluz Nov 07 '10 at 23:32
  • 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. – Lior Iluz Nov 08 '10 at 06:41
  • 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. – Reuben Scratton Nov 08 '10 at 09:47
  • @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 :) – Lior Iluz Nov 08 '10 at 09:55
  • 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. – Lior Iluz Nov 08 '10 at 19:52

2 Answers2

5

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);
Dharman
  • 30,962
  • 25
  • 85
  • 135
Lior Iluz
  • 26,213
  • 16
  • 65
  • 114
3

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
user1010
  • 369
  • 1
  • 5
  • 18