How To Make Contentobserver Work Without Having Application Opened?
I need to have my application listen for changes in addressbook in Android. I have read that it can be done using ContentObserver and listening for changes in ContactsContract.Cont
Solution 1:
How do I make the ContentObserver work even if the application wasn't opened?
That is not possible. The point behind a ContentObserver
is to be notified of changes that might affect a running app, such as changes to data that need to be reflected in an activity showing that data. If your app is not running, you cannot have a ContentObserver
.
Solution 2:
register your Content Observer in the OnStartCommand with return START_STICKY;
instead of registering it in the onCreate. It works for me.
@OverridepublicintonStartCommand(Intent intent, int flags, int startId) {
getContentResolver().registerContentObserver(uri,true, newSMSObserver(newHandler(), getBaseContext()));
return START_STICKY;
}
Post a Comment for "How To Make Contentobserver Work Without Having Application Opened?"