Are content observers persistent in Android? If I create a content observer in an activity, will that observer continue to run until I remove the observer.
Basically I am creating a service for SMS, where on receive and on send I post the SMS out to a web service, so I can check my messages with out having my phone.
If the content observer is tied to the Activity’s life, how can I create a ContentObserver that will always receive notifications on content:/sms/
Only if you like leaking memory, and then only until Android terminates the process. Well-behaved activities will not register content observers without unregistering them at an appropriate time (e.g.,
onDestroy()).The SMS content provider is not part of the SDK. It may or may not work on your phone. It may or may not work in future versions of Android.
The only way to have a
ContentObserverthat sticks around for a bit is to have it be in aService. However, services do not live forever, either. Beyond that, there is no way to have an observer “always receive notifications”.Sorry!