I am working on the app that runs in background and need to call api for every 1 minute(60*1000 millisecond) without any fluctuations. I have tried Scheduler,timer and things but it is not working proper. For example, my scenario is to call the api on 09:11:36 am(first api call),09:12:36 am(second api call) and so on and at the end the final api call will be at 11:20:36 pm. I used below code :
Handler minuteHandler = new Handler();
minuteHandler.postDelayed(runnable, 60000);
final Runnable runnable = new Runnable() {
@Override
public void run() {
// your runnable code
minuteHandler.removeCallbacks(runnable);
minuteHandler.postDelayed(runnable, 60000);
}
};
and
new Timer("threadname", true).scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
// your runnable code
}
}, 0,60*1000);
etc., My question is that it is possible to achieve in android(all OS vesions).