0

I am using this code to broadcast alarm for a specific day. But it is ringing for everyday. Can any one help me on this?

calendar.set(Calendar.HOUR_OF_DAY, hours);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.DAY_OF_WEEK, weekdayList.get(x));
Intent myIntent = new Intent(getApplicationContext(), AlarmReceiver.class);
myIntent.putExtra("reminder_id",value+"");
myIntent.putExtra("reminder_title", title.getText().toString());

pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), value1, myIntent, PendingIntent.FLAG_CANCEL_CURRENT);


//  alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
          calendar.getTimeInMillis(), 1000 * 60  * 60, pendingIntent);
Martin Zabel
  • 3,589
  • 3
  • 19
  • 34
dc.boy
  • 55
  • 9
  • 1
    Please show the types of all your variables. Better, make it a [minimal, complete, and verifiable example.](http://stackoverflow.com/help/mcve). – Martin Zabel Mar 02 '16 at 21:25
  • I needed a solution to such a problem for one of my apps; an answer would be great help – Eenvincible Mar 02 '16 at 22:45
  • i got a solution here. it worked for me. i have to use sqlite database for that. http://stackoverflow.com/questions/14272295/how-can-i-get-the-repeat-alarm-for-week-days-using-alarm-manager – dc.boy Mar 03 '16 at 21:28

1 Answers1

0

If you want to schedule it only once:

alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);

If you want to repeat it weekly:

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
      calendar.getTimeInMillis(), alarmManager.INTERVAL_DAY * 7, pendingIntent);

Remember to take caution when setting you calendar variable. According to DOCS:

For set()

If the stated trigger time is in the past, the alarm will be triggered immediately. If there is already an alarm for this Intent scheduled (with the equality of two intents being defined by filterEquals(Intent)), then it will be removed and replaced by this one.

For setRepeating()

If the stated trigger time is in the past, the alarm will be triggered immediately, with an alarm count depending on how far in the past the trigger time is relative to the repeat interval.

guipivoto
  • 18,327
  • 9
  • 60
  • 75
  • got a solution here. thanks any way :) http://stackoverflow.com/questions/14272295/how-can-i-get-the-repeat-alarm-for-week-days-using-alarm-manager – dc.boy Mar 03 '16 at 21:30