I implemented content observer of history but it is behaving weird.For every change in history its onChange() function runs 3-5 times.
static class BrowserOberse
The exact way in which history is updated is an implementation detail you probably do not want to be relying on. Rather than trying to guess whether the update is finished or not based on the values of various fields, I would suggest restarting a timer each time onChange(..)
is called. If the timer expires, you can be reasonably certain that history has finished updating.
Edit Example of how to use a timer:
static class BrowserOberser extends ContentObserver implements Runnable {
private Handler h;
public BrowserOberser() {
super(null);
h = new Handler();
}
@Override
public boolean deliverSelfNotifications() {
return true;
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
h.removeCallbacks(this);
h.postDelayed(this, 500);
}
public void run() {
Log.d("history observer", "change timer elapsed");
}
}