Search code examples
androidbroadcastreceiverandroid-sensorswakelock

Cannot keep sensor update rate after screen-off


My application needs to collect data from both sensors and GPS, but it seems that after I turn the screen off, the update rate slows down considerably (to 500ms, down from 20ms, or stops completely, in another phone).

I've read several workarounds: one of them involved using a wake-lock, to keep the process running, and another that says to register a broadcast receiver to re-register the event listeners after a screen-off event.

Both don't return errors while executing, but somehow the sensors stop behaving exactly after the screen turns off (and coincidentally, they start behaving right after I press the power button, nevermind unlocking the screen).

I'm registering the BroadcastReceiver from within an activity, to the "ACTION_SCREEN_OFF" event, an acquiring the wake lock from there aswell, on the 'onCreate'method.

I'm using a Lenovo A60 with Android 2.3.5, and an LG Optimus Pro with Android 2.3.4.


Solution

  • At this time, there are two possible answers to this question:

    1. If your cellphone is a part of this list (or one that still isn't, but has a similar underlying sensor implementation), then you can use the method described here to implement a workaround using BroadcastReceivers to restart sensor listening after the screen turns off;
    2. You can use a wake-lock or another method to keep the screen on and use a "press back twice to exit" schemes in order to safeguard the user from closing the activity