-1

I want the android app to sync with the server every 30 (or any interval) minutes and notify user if there is any change.

I have already tried [JobScheduler][1]. It seems like [JobScheduler][1] runs the event at optimized interval not at exact interval. Some one suggested [AlarmManager][1] but i don't think that will also work - It also checks the battery optimization. (setExactTime and setExactAndAllowWhileIdle also runs at optimized time)

I want the app to sync with the server at exact interval no matter what.

Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104

1 Answers1

0

You can use timer for this

Timer timer = new Timer();

Then you extend the timer task

class SyncData extends TimerTask {


   public void run() {
       //call after every 30min
   }
}

And then add the new task to the Timer with some update interval

TimerTask syncData = new SyncData();
timer.scheduleAtFixedRate(syncData,1000*10);//this will run after every 10 sec

Note: It will only work if your application is not in background if you want to call api when your application is in background than please user Service and AlaramManager.

Lokesh Desai
  • 2,607
  • 16
  • 28