1

I'm trying to add a new bookmark in my web browser, the bookmark is succefully added, but, the program throw an exception after adding the bookmark, I explain :

When Browser.saveBookmark is called , I can fill url and title values and then select "save". The item is successfully added to the list. Then, The message displays: "Sorry! The application Browser (process com.android.browser) has stopped unexpectedly. Please try again."

Here is my source code :

@Override  
public boolean onOptionsItemSelected(MenuItem item) {  

if (item.getItemId() == MENU_ADD) {  
    Browser.saveBookmark(this, "New Bookmark", "http://");  
    return true;
} else
    return false;
} 

The stack trace in Logcat is as follows :

  01-03 14:47:25.862: ERROR/AndroidRuntime(1720): FATAL EXCEPTION: Thread-11
  01-03 14:47:25.862: ERROR/AndroidRuntime(1720): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
  01-03 14:47:25.862: ERROR/AndroidRuntime(1720):     at android.os.Handler.<init>(Handler.java:121)
  01-03 14:47:25.862: ERROR/AndroidRuntime(1720):     at android.webkit.WebIconDatabase$EventHandler.<init>(WebIconDatabase.java:46)
  01-03 14:47:25.862: ERROR/AndroidRuntime(1720):     at android.webkit.WebIconDatabase$EventHandler.<init>(WebIconDatabase.java:46)
  01-03 14:47:25.862: ERROR/AndroidRuntime(1720):     at android.webkit.WebIconDatabase.<init>(WebIconDatabase.java:43)
  01-03 14:47:25.862: ERROR/AndroidRuntime(1720):     at android.webkit.WebIconDatabase.getInstance(WebIconDatabase.java:293)
  01-03 14:47:25.862: ERROR/AndroidRuntime(1720):     at com.android.browser.Bookmarks.addBookmark(Bookmarks.java:136)
  01-03 14:47:25.862: ERROR/AndroidRuntime(1720):     at com.android.browser.AddBookmarkPage$SaveBookmarkRunnable.run(AddBookmarkPage.java:136)
  01-03 14:47:25.862: ERROR/AndroidRuntime(1720):     at java.lang.Thread.run(Thread.java:1096)

I have already tried this way to add a bookmark (instead Browser.saveBookmark) :

  Intent i = new Intent(Intent.ACTION_INSERT, android.provider.Browser.BOOKMARKS_URI);
  i.putExtra("title", title);
  i.putExtra("url", url);
  this.startActivity(i);

But, this gave me the same error!

So, any workaround on this bug or any other solution to add a bookmark? Thanks in advance

Alaoui Ghita
  • 1,859
  • 4
  • 22
  • 26

1 Answers1

2

Edit:

Change this:

if (item.getItemId() == MENU_ADD) {  
   Browser.saveBookmark(this, "New Bookmark", "http://");  
   bookmarkAdapter.notifyDataSetChanged();
   return true;
} else
   return false;
} 

With this

if (item.getItemId() == MENU_ADD) {  
   Intent i = new Intent(Intent.ACTION_INSERT, android.provider.Browser.BOOKMARKS_URI);
   i.putExtra("title", title);
   i.putExtra("url", url);
   this.startActivity(i);
   return true;
} else
   return false;
} 

and try it.

Esselans
  • 1,540
  • 2
  • 24
  • 44
  • Aw, you didn't mention that detail. This is not the answer. – Esselans Jan 03 '12 at 20:41
  • I was wrong Ragetzaz, so the code that you gived me do the same thing that the method Browser.saveBookmark(..), BUT when I tried it, it gave me the same error :( – Alaoui Ghita Jan 03 '12 at 21:12