Am creating an application that fetch data from webservice. I have been while(true)
and sleeping the loop at a specific milliseconds.. i had like to make the service action(fetching data from webservice) to always start at a specific time.. instead on being on always and pausing by Thread.sleep(milli)
... Thanks
this is what have been using
while(true)
{
///pullDataFromWebservice();
Thread.sleep(600000);
}
Try using AlarmManager - A bit battery eater though
Use the Alarm API. It is way safer than having a sleep & poll service.
Why?
Because Android is very likely to reclaim such a long running services when resources turn low, resulting in your delayed logic never being called!
An example for activating a callback in 1 hour from now: