Running an Activity a certain interval before going to sleep
<p>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).</p>

<p>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).</p>

<p>My initial searches have lead me to the PowerManagerService class, where the ACTION_SCREEN_OFF is broadcast, but the general idea of the code there has so far eluded me.</p>

<p>Any help would be appreciated.
Thank you.</p>
