I have a content observer detecting onChange successfully when the application is running in the foreground. I want to kill my application (swipe it away) but still have this content observer be able to detect onChange. I have tried many many things, but need help achieving the dream scenario.
Start a foreground service (which forces a permanent notification), and registers the content observer in the foreground service. This method "works" but I really hate that permanent notification. My app currently work this way and I get complaints about the notification, thus my motivation to find a better method.
Start a background service, keep it sticky. This does not work, because in newer version of Android, even sticky services gets killed after your main app gets killed
Start a background service, on its onDestroy() method, send broadcast to restart the service. Basically read this guide. This doesn't really work either, my service restarts a couple of times, then I get errors which basically says I am trying to restart my service too many times.
Start a background service, which starts a thread that runs forever. In the thread, do the content observer. I haven't tested this method yet, but it seem really bad because It will probably create orphaned threads, just seems really bad coding practice. Has anything tried something similar?
So basically the issue newer and newer Android is recycling services in almost all situations. How do I keep a background service running forever, because I need a content observer to run forever and listen to changes.