开发者

Android - Execute action when phone is locked

开发者 https://www.devze.com 2023-01-17 13:44 出处:网络
I want to know how I can execute some action, or continue listening to sensor or battery change events when th开发者_如何学Pythone phone is locked. (When the phone is locked it stops listening to sens

I want to know how I can execute some action, or continue listening to sensor or battery change events when th开发者_如何学Pythone phone is locked. (When the phone is locked it stops listening to sensor changes.)

I've tried with wakelocks but I it doesn't work (maybe I'm using it wrong).

Any help would be appreciated.


I'd recommend using a service for that. They run in background even while the phone is locked.

Here is the reference along with some explanation on Android Services


Wakelocks are a pain in the neck. I recommend giving CommonsWare's WakefulIntentService a try.

0

精彩评论

暂无评论...
验证码 换一张
取 消