I am trying to add functionality to my app to monitor the app's database (via MyContentProvider) for new items. So I've create a MyContentObserver which, as new items are added to the database, will:
- Update the badge/counter on the app's launcher icon with the number of new items.
- Store that same integer in SharedPreferences, so it can be accessed by other components of the app (e.g., by Activities/Fragments to display on their UI, and by
MyApplicationto set the app icon's badge/counter when the device reboots).
I have tried registering MyContentObserver in the onCreate() method of MyApplication, but it does not seem to be a reliable way of doing it.
Whilst trying to research the correct way of doing it, I've seen some SO posts describing how some developers have tried implementing a Service (instead of MyApplication) to meet the objective, but most of these developers are also citing problems.
As there does not appear to be a guide anywhere on this, can someone recommend the proper way to set up a ContentObserver for it to monitor constantly and dependably?