开发者

Running an Activity a certain interval before going to sleep

I am currently working on customizing an Android system and would like that, a few minutes before going to sleep, a given Activity is run, with the same premises as the sleep function (e.g. if the user performs any action, its timer gets reset).

For instance, let's say that we set its timer to 5 minutes and the device is set to go to sleep after 10 minutes. This means that, as long as there is no user input (or wakelocks acquired etc.), after 5 minutes my Activity is started, and after another 5 minutes the device enters sleep mode (think of it similar to a screensaver).

My initial searches have lead me to the PowerManagerService class, where the ACTION_SCREEN_OFF is broadcast, but the genera开发者_StackOverflow社区l idea of the code there has so far eluded me.

Any help would be appreciated. Thank you.


This is not possible, sorry. You have no way of determining system-wide inactivity up until the ACTION_SCREEN_OFF broadcast is sent.


Maybe you can use Wakelock to delay the sleep.

  1. implement a broadcastreceive , filter the ACTION_SCREEN_OFF
  2. when receiving the ACTION_SCREEN_OFF , lock the PARTIAL_WAKE_LOCK
  3. do what you want....
  4. when you finish all the job, release Wakelock. then system go to sleep.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜