What is wrong with that? it does not start the service after 5 minutes. Only send it after 1 minute

This should start the service after 5 minutes, but its start after 1 minute

Intent myIntent = new Intent(getApplicationContext(), BackgroundDataSender.class); PendingIntent piHeartBeatService = PendingIntent.getService(this, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(piHeartBeatService); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), (5*60*1000) , piHeartBeatService); 
+4
source share
2 answers

You must write:

 alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (5*60*1000), (5*60*1000) , piHeartBeatService); 

if you want your alarm to start after 5 minutes (and repeat every 5 minutes after that) ...

0
source

try it

 private static final long UPDATE_INTERVAL=300000; Calendar cal=Calendar.getInstance(); cal.add(Calendar.MINUTE,0); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(),UPDATE_INTERVAL,pendingIntent); 
0
source

Source: https://habr.com/ru/post/1434578/


All Articles