Diego
Diego

Reputation: 651

Android - Execute action when phone is locked

I want to know how I can execute some action, or continue listening to sensor or battery change events when the 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.

Upvotes: 4

Views: 713

Answers (2)

benvd
benvd

Reputation: 5784

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

Upvotes: 1

Octavian Helm
Octavian Helm

Reputation: 39603

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

Upvotes: 2

Related Questions