PotatoesPower PotatoesPower - 1 month ago 5
Java Question

Execute a task all x seconds

I have an

who send notification when my value
live == true

But how i can do for :
Launch every x seconds this activity in background.

Exemple : If the app is in background task but not running, she will execute this class all x seconds in background.

This app send a notification when my value is on
. But i need to refresh this result all 15m (15000 ms i think).

Thank you for your help.


First of all, you need to check the Activity lifecycle so that you will know how to determine if an activity is in the background.


Once your are clear with that, you can use ScheduledExecutorService to schedule your class.