For a proof of concept, I need to be able to capture whether the phone gets interactive, and the other way around. So far, I tried following methods:
with BroadcastReceivers capturing SCREEN_OFF and SCREEN_ON events, but this only works when the app is running. If I try to add it to the manifest, I won't be able to capture the events if the app is not running (Android policies)
Scheduling jobs. With this technique, Instead of suscribing to the events, I can check the status of the screen at the moment the job is running. Problem? for Nougat devices, the minimum periodic time I can specify for the job to run is every 15 min, which is too much for my proof of concept.
I haven't tried services yet, as I read in the documentation that this might not be the best way to do this. Quoting Android documentation:
You should avoid using started services that run perpetually or perform periodic work, since they continue to use device resources even when they are not performing useful tasks. Instead, you should use other solutions that this page describes, and that provide native lifecycle management. Use started services only as a last resort. The Android platform may not support started services in the future
Am I looking at this the wrong way? Do you guys advice to go for the service (in this case, I would prefer to use background service).