I have deployed your example as is and it works great.
package com.test.contentobserver; import android.app.Activity; import android.database.ContentObserver; import android.os.Bundle; import android.provider.Contacts.People; public class TestContentObserver extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); this.getApplicationContext().getContentResolver().registerContentObserver (People.CONTENT_URI, true, contentObserver); } private class MyContentObserver extends ContentObserver { public MyContentObserver() { super(null); } @Override public void onChange(boolean selfChange) { super.onChange(selfChange); } } MyContentObserver contentObserver = new MyContentObserver(); }
So you have to do something else wrong.
Do you make changes through the cursor to which the observer is registered?
Make sure the Observer deliverSelfNotifications () function. (by default it returns false)
You can override this observer function with something like:
@Override public boolean deliverSelfNotifications() { return true; }
Make sure People.CONTENT_URI is referencing the correct value (android.provider.Contacts.People).
In addition, I would suggest you use Handler with ContentObserver, although this does not make your code incorrect in this case.
MannyNS Sep 09 '09 at 23:39 2009-09-09 23:39
source share