PotatoesPower PotatoesPower - 1 year ago 78
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.

Answer Source

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.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download