The problem, I suspect, is that ContentObservers only work while your
process is running. If your process finishes and its memory is garbage
collected then you won't be notified. I believe the memory for your
ContentObserver instance is allocated within your process. So when the
system tries to call onChange on your ContentObserver instance it
finds it no longer exists. If this *is* the case you should see an
error message in logcat about a dead observer.

Cheers,
Justin
Android Team @ Google

On Mar 31, 5:21 pm, Peli <[EMAIL PROTECTED]> wrote:
> It seems, myContentObserverdoes not tell me if data are changed by a
> different process? Or maybe I'm doing something wrong:
>
> I have an activity in which I register aContentObserver:
>
> ----------------------------
> mCursorListFilter = getContentResolver().query(Lists.CONTENT_URI,
>                 myFilter,
>                 null, null, Lists.DEFAULT_SORT_ORDER);
>         startManagingCursor(mCursorListFilter);
>
>         class mListContentObserver extendsContentObserver{
>                 public mListContentObserver(Handler handler) {
>                   super(handler);
>                 }
>                 @Override
>         public void onChange(boolean arg0) {
>           Log.i(TAG, "mListContentObserver: onChange");
>           mCursorListFilter.requery();
>           super.onChange(arg0);
>         }
>
>         };
>
>         mCursorListFilter.registerContentObserver(new
> mListContentObserver(new Handler()));
> ----------------------------
>
>   I do receive the LogCat events onChange if data are changed from
> within the same activity.
>
> However, when I change the data through a separate IntentReceiver that
> receives Intents in the background, I don't receive onChange events,
> and my data in my ListViews don't get updated.
>
> In the IntentReceiver I do something like this:
>
> ----------------------------
> public void onReceiveIntent(Context context, Intent intent) {
>   [...]
>    Cursor c = mContentResolver.query(
>                         Shopping.Lists.CONTENT_URI,
>                         mProjectionLists,
>                         Shopping.Lists.SHARE_NAME + " = '" + shareListName +
> "'",
>                         null,
>                         Shopping.Lists.DEFAULT_SORT_ORDER);
>
>        [...]
>      c.first();
>      c.updateString(mProjectionListsSHARECONTACTS, shareContacts);
>      c.commitUpdates();
>      c.requery();}
>
> ----------------------------
>
> The data are changed in the database. If I exit my activity and start
> it again, I see the new data. Just they don't get updated "live" while
> the IntentReceiver receives the data in the background.
>
> Is aContentObserversuitable for these cases, or is it only made to
> notify within one activity? Should I use other methods so that the
> IntentReceiver can notify the main Activity (if running)?
>
> Peli
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to