I have "Call Log Widget" on the Android Market:
http://blog.zedray.com/call-log-widget/

The core of this Widget is an AppWidgetProvider which registers a
ContentObserver to the CallLog content URI.  This means that my widget
is updated every time a call (incoming, outgoing, missed) is
recorded.  This works fine for a while, until *something happens* and
my ContentObserver stops getting called (no error message seen in
trace).  I would rather that this ContentObserver persisted until the
user removes the Widget.

I am guessing that my JVM has been destroyed (due to low memory?),
ContentObserver garbage collected and/or ContentObserver unregistered
(or just pointing to nothing), but I don't know how to debug this
without restarting my code (and thereby re-registering).

I can hide this bug by periodically re-registering my Content
provider, but I would rather understand the cause and have a more
optimal solution.

Feedback appreciated.
Mark

### Code snippet ###
public class CallLogWidgetProvider extends AppWidgetProvider {
    /** Making this static is an attempt to prevent duplicate
ContentObserver registrations. **/
    private static CallObserver sCallObserver;

   /** Method called by onEnabled() and onUpdate(). **/
    private void registerCallObserver(Context context) {
        if (sCallObserver == null) {
            sCallObserver = new CallObserver(null,
context.getApplicationContext());
 
context.getContentResolver().registerContentObserver(CallLog.Calls.CONTENT_URI,
true, sCallObserver);
        }
    }

 private class CallObserver extends ContentObserver {
        private Context mContext;

        public CallObserver(Handler handler, Context context) {
            super(handler);
            mContext = context;
        }

        @Override
        public void onChange(boolean b) {
            /** Update all widgets due to a change in content. **/
            callOnUpdate(mContext);
        }

    //... widget code ...
    }
### Code snippet ###

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to