Reputation: 936
My application uses below code to set Alaram to execute service on "Daily" basis.
AlarmManager alarmManager = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(ctx, SchedulerEventReceiver.class); // explicit// intent
Calendar now = Calendar.getInstance();
now.add(Calendar.SECOND, 20);
PendingIntent intentExecuted = PendingIntent.getBroadcast(ctx, new Random().nextInt(), i,PendingIntent.FLAG_CANCEL_CURRENT);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, now.getTimeInMillis(), AlarmManager.INTERVAL_DAY, intentExecuted);
adb shell dumpsys alarm
shows me proper details. like it is scheduled to run daily. However when i install .apk to my phone, it is executing repeatedly. it doesnt wait for a day to execute.
I dont know how to reset alarm set in my phone. i uninstalled the app and newly installed app, but it didn't work. can someone tell me what is wrong?
Upvotes: 0
Views: 1128
Reputation: 2254
i have used this and this is working fine for me. i have used this alarm to trigger after 18 days. and then again after 18 days and so on:
long time = 1555200000L; //18 days = 18*24*60*60*1000 = 1555200000L
AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, MyReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(context, tag, i, PendingIntent.FLAG_CANCEL_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+time, time, pi);
Upvotes: 1