Wakelock and doze mode

后端 未结 4 1271
一整个雨季
一整个雨季 2020-11-30 05:26

According to Android Marshmallow documentation when the system is in doze mode, any wakelock is ignored. However it\'s not clear to me if a wakelock prevent doze mode or not

4条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 05:38

    As far as I have explored, all wake locks (except the ones held by apps with a current foreground service) are dropped when the deeper doze starts. The whole point of doze is to let the system sleep when the 'relevant conditions' set in. So yes locks is not something they would care too much about I guess.

    The way I see it JobScheduler is the way to go about scheduling, background tasks etc in future. Takes some control away from developers though but that's the call I guess framework guys took for battery life. It's more like 'trigger and hope things will happen more or less on time'.

    Coming to your use case, JobScheduler has an onStopJob callback to know when the execution of your job has stopped [for any reason - say wifi was toggled] you need to take appropriate action such as rescheduling your job for the next maintenance window. From the docs:

    One immediate repercussion is that the system will cease holding a wakelock for you.

提交回复
热议问题