Question

I am developing an app to show the user the "number of messages sent" so that they can manage their free quota without over running it. I did some research and with that I am able to register a ContentObserver from a Service to Observe the sms URI. It would be helpful if some one could give me the following information:

  1. Is it ok to start this service on BOOT_COMPLETE
  2. Should I unregister the contentObserver at some point, if so when?
  3. Should I run the 'registerContentObserver' on a new Thread?

Note: Inside my Observer, for a Sent SMS, I will just update a value in an MySQL Database.

Was it helpful?

Solution

I have implemented my requirement with research and help from the G+ Android Developer community. You can see the implementation at the below links from GitHub.

And based on my experiences, I am giving the answers as below.

  1. It is ok to start a service on BOOT_COMPLETE, but better wait some time (10 seconds) so that we don't load the system as many other services may get started and as such.
  2. We can unregister the contentObserver in the onDestroy method of the service
  3. I was able to do 'registerContentObserver' on a UI thread without any issues?

https://github.com/midhunhk/message-counter/tree/master/v2/MessageCounter/src/com/ae/apps/messagecounter/observers https://github.com/midhunhk/message-counter/tree/master/v2/MessageCounter/src/com/ae/apps/messagecounter/services

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top