Contentobserver Not Working In Android
Solution 1:
A ContentObserver only works with a ContentProvider that calls one of the notifyChange() methods on a ContentResolver when the contents of the provider change. If the ContentProvider does not call notifyChange(), the ContentObserver will not be notified about changes.
Solution 2:
Problem
The problem I experienced was that the ContentObserver.onChange() method never got called because the ContentObserver's Handler's Looper was initialized improperly. I forgot to call Looper.loop() after calling Looper.prepare()...this lead to the Looper not consuming events and invoking ContentObserver.onChange().
Solution
The solution is to properly create and initialize a Handler and Looper for the ContentObserver:
// creates and starts a new thread set up as a looper
HandlerThread thread = newHandlerThread("MyHandlerThread");
thread.start();
// creates the handler using the passed looper
Handler handler = newHandler(thread.getLooper());
// creates the content observer which handles onChange on a worker thread
ContentObserver observer = newMyContentObserver(handler);
useful SO post about controlling which thread ContentObserver.onChange() is executed on.
Post a Comment for "Contentobserver Not Working In Android"