I tried using
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
executor.scheduleWithFixedDelay(new Runnable(){
public void run() {
// update server (method which has asyncTask)
}
}, 0, 600, TimeUnit.SECONDS);
And it stops working after mobile sleeps. I would like to do the same using alarmManager but I dont know if I should use service,broadcast service or activity for the requirement above.
Please help me out.
Thanks in advance.
Since you are going to be networking, i would recommend you to use a Service. If you don’t need to keep state in between executions, or don’t want to deal with threads manually, use an IntentService
This is the code i’m using to set up the a polling service: