ContentObserver onChange() on Android 2.x not get called

327 Views Asked by At

I have a ContentObserver which I have tested on android 4.x and it worked well. But when I tried it on android 2.x it doesn't work.

mContentObserver = new ContentObserver(new Handler()) {
            @Override
            public void onChange(boolean selfChange, Uri uri) {
                if (CardDAO.MANAGEMENT_URI.equals(uri) || SubjectDAO.MANAGEMENT_URI.equals(uri)
                        || LearningProgressDAO.MANAGEMENT_URI.equals(uri) || ActivationDAO.MANAGEMENT_URI.equals(uri)) {
                    onContentChanged();
                }
            }
        };
1

There are 1 best solutions below

0
On

It appeared that there is no such method public void onChange(boolean selfChange, Uri uri) in android 2.x . The solution is to use method which is in old API public void onChange(boolean selfChange)

HERE is the difference between two versions

2.x:

private final class More ...NotificationRunnable implements Runnable {

        ...................

     public void run() {
         ContentObserver.this.onChange(mSelf);
     }
 }

4.x:

private final class NotificationRunnable implements Runnable {

       ................................

    @Override
    public void run() {
        ContentObserver.this.onChange(mSelfChange, mUri, mUserId);
    }
}