browser - Android History Content Observer -


i implemented content observer of history behaving weird.for every change in history onchange() function runs 3-5 times.

static class browseroberser extends contentobserver {     public browseroberser() {         super(null);     }      @override     public boolean deliverselfnotifications() {         return true;     }      @override     public void onchange(boolean selfchange) {         super.onchange(selfchange);         log.d("history", "onchange: " + selfchange);     }  } 

i registered observer using

browseroberser observer = new browseroberser(); getapplication().getcontentresolver().registercontentobserver(browser.bookmarks_uri, true, observer ); 

and added required permissions in manifest.

the code works fine onchange(); runs 3-5 times each change in history
can me out solution problem?

this how solved problem case atleast(i wanted read history when there change in history)

    @override     public void onchange(boolean selfchange) {         super.onchange(selfchange);         /**          * sharedpreferneces of user          */         sharedpreferences pref= mycontext.getsharedpreferences("com.tpf.sbrowser",                  context.mode_private);         long wherelong = pref.getlong("date", 0);         databasemanager db=new databasemanager(mycontext,1);         string[] proj = new string[] { browser.bookmarkcolumns.title,                 browser.bookmarkcolumns.url, bookmarkcolumns.date,};         string sel = browser.bookmarkcolumns.bookmark + " = 0";          cursor mcur = mycontext.getcontentresolver().query(                 browser.bookmarks_uri, proj, sel, null, null);         log.d("onchange", "cursorcount"+mcur.getcount());         mcur.movetofirst();          string title = "";          string url = "";          long lastvisiteddate=0;         dbmessage msg = new dbmessage(lastvisiteddate,url, title);         /**          * start reading user history , dump database          */         if(mcur.movetofirst() && mcur.getcount() > 0) {                while (mcur.isafterlast() == false) {                   title =mcur.getstring(0);                    url = mcur.getstring(1);                    lastvisiteddate =mcur.getlong(2);                    if ((lastvisiteddate>wherelong) && (!title.equals(url))) {                       msg.set(lastvisiteddate, url, title);                       db.insertwithoutend(msg);                       pref.edit().putboolean("browserhistoryread", true).commit();                       pref.edit().putlong("date", lastvisiteddate).commit();                       mycontext.updatetime(wherelong,lastvisiteddate);                       wherelong=lastvisiteddate;                   }                   mcur.movetonext();                }            }     } 

but still if great if tell iteration of onchange(in simple code of question) corresponds state in page loading. learned, in first iteration title same url , in third iteration correct page title present. during redirection, onchange got called upto 5 times. can confirm iteration coressponds stage?


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -