I want to have a periodically task that should be run every 30 seconds. so I'm using ScheduledThreadPoolExecutor
or Timer
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
executor.scheduleWithFixedDelay(new MyTask(), 0, 30000, TimeUnit.MILLISECONDS);
class MyTask implements Runnable {
@Override
public void run() {
}
}
Here is Timer
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
// do something here
}
}, 0, 30000);
My question is: is there any differences if I start above code inside Service/IntentService or inside one activity. Those actions will be same or start inside service will better.