Android : Service/Activity should start after some time, while the screen is off and in my pocket
I'm having the problem that I want to have a service/activity running after some time, afte开发者_如何学Cr I turned off the screen and put the phone into my pocket.
I don't want to use wakelocks all the time to count the time myself (c.f. battery).
Is there somewhere a system timer, which can call my app to wake up and accquire the wakelock then. (screen is off all time and in my pocket)
Is there somewhere a system timer
Yes. It's called an alarm. See AlarmManager. From there:
This class provides access to the system alarm services. These allow you to schedule your application to be run at some point in the future. When an alarm goes off, the Intent that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running. Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.
you will get a broadcast when screen turns off then you can set timer or alarm manager.
((screen is off all time and in my pocket)) but you didn't get any broadcast for device is in your pocket :)
精彩评论