I just started working coverting my iOS app to Android.
But I’m having the following problem.
I created multiple classes so the alert pops-up.
But the problem is that the alert pop-ups every 5/10 seconds instead of the given time.
I know this has something to do with the following code:
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime() + 5000, 10000, pendingIntent);
But the strangest thing is that the given time above that code doesn’t trigger any thing:
(Otherwise I could’ve just deleted the last line of code)
private void setRecurringAlarm(Context context) {
Calendar updateTime = Calendar.getInstance();
updateTime.set(Calendar.HOUR_OF_DAY, 17);
updateTime.set(Calendar.MINUTE, 18);
Intent open = new Intent(this, AlarmReceiver.class);
open.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, open, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(MyApp.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime() + 5000, 10000, pendingIntent);
What’s wrong with that code because the alarm doesn’t pop-up at 17:18 but each time after 5 or 10 seconds.
The service that i’ve created to display the notification doesn’t start at 17:18 to display the message.
Does this has something to do with my timezone (Amsterdam Time)?
I think you’re passing in the wrong values for .setRepeating. Have a look at the documentation
It looks to me like you’re saying:
broadcast for the first time 5 seconds from now, then every 10 seconds after that repeat