I'm developing an application that start a service to execute an action when the ambient light changes. Here is the cinematic:
Activity A
On Start --> If Service S running, start Activity B
On Click --> Start Service S (not an IntentService) using starService.
Activity B
On Start --> Bind to Service S
On Click --> Stop Service S
Service S implements SensorEventListener
On Create --> Register to light sensor
On Sensor Changed --> Write a log
On Destroy --> Unregister to light sensor
My problem is: When you launch the application and start the service, everything is fine. When the screen is turned off, Service S does not receive notifications from the light sensor anymore. When I turn the screen back on, no notifications are received either. If I destroy the Service and start it again within the same application session, notification are not received.
Documentation on sensor are not very helpful (or maybe I missed something). Can anyone help?