Reputation: 59
I wanna run my service only when device is not locked.How exactly it has to work:
User runs the application.
Then service is run
I'm in need of help with first 3 points. Because fourth point can be done with ACTION_USER_PRESENT
. Help me please.
Upvotes: 0
Views: 232
Reputation: 11608
1) You can start a Service
by calling startService(Intent)
from onCreate()
or onStart()
of your first Activity
(alternatively, from onCreate()
of your Application
class).
2) Your Service
is already running
3) To do so, you will need to detect the device lock event. The only approach I can think of here is listening for the ACTION_SCREEN_OFF
. You can find a detailed example in the accepted answer of this question.
After you have detected the screen off action, you can stop your Service by calling stopService(Intent)
Upvotes: 2