Search code examples
androidservicebroadcastreceiverandroid-notificationscountdowntimer

How to create a notification every x minutes a user is continuously using his/her device


I want to create a notification every x minutes a user is continuously using his/her device.

I think I'm supposed to use a background service that will listen for when the screen turns on, then I can start some sort of timer that will trigger a notification if the screen hasn't been off for x minutes (user entered time value).

I don't necessarily need a spoon-fed answer but some very clear direction or documentation would be extremely helpful because I have no idea what I'm doing! :)


Solution

  • to detect screen on:

    Intent.ACTION_SCREEN_OFF and ACTION_SCREEN_ON check out for above broadcasts registration. here https://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/ you can find a good example.

    when screen is on set an alarm for x time as you want here How do I repeat a method every 10 minutes after a button press and end it on another button press user the accepted answer. When alarm time reaches check if the screen is still on if it is, create a notification. when the screen goes off turn of this alarm.