Reputation: 67
I'm using simple ScheduledExecutorService implementation and everything is working fine.But when I open other application like google chrome or game my application scheduler stop and android debug console go empty. Btw onPause and onStops method I start beepForAnHour() method.
import static java.util.concurrent.TimeUnit.*;
class BeeperControl {
private final ScheduledExecutorService scheduler =
Executors.newScheduledThreadPool(1);
public void beepForAnHour() {
final Runnable beeper = new Runnable() {
public void run() { System.out.println("beep");
};
final ScheduledFuture beeperHandle =
scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS);
scheduler.schedule(new Runnable() {
public void run() { beeperHandle.cancel(true); }
}, 60 * 60, SECONDS);
}
}}
Upvotes: 2
Views: 561
Reputation: 50588
ScheduledExecutorService
runs on same process id as your application, i.e it is bonded to live as long as your application lives. You should use different approach to keep your ScheduledExecutorService
alive, like starting it from a Service
or use other independent scheduled method like AlaramManager
.
Upvotes: 2