androidalarms

two alarms set at same time


in my application users are free to select time and date to set alarms . What will happen if user choose exactly the same date and time for two alarms. I am taking input from user(for date and time) and setting the alarm.

       GregorianCalendar  gc=new GregorianCalendar();
       gc.set(2012, 1, 22, 11, 19,0);//values as given by the user

       final Intent intent = new Intent(this, AlarmService.class);
       gc.set(Calendar.AM_PM,0);

     //  final PendingIntent sender = PendingIntent.getBroadcast(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);

       am.set(AlarmManager.RTC_WAKEUP, gc.getTimeInMillis(),PendingIntent.getBroadcast(this,1, intent, PendingIntent.FLAG_UPDATE_CURRENT));

I have used a broadcastreceiver to recieve the alarm broadcast. How should I handle this situation. What should I prefer to do? I want to know the tecchnical aspect as what happens in this situation.


Solution

  • AFAIK,it won't create any technical problem for alarms set for the same time.It will fire all alarms at the same time.

    It depends upon you how you want your user to set alarm.If you want them to set same time for various alarms,it's not a problem.

    But if you don't want them to repeat the alarm time once it is set for other,then you can store alarms' time in database and at the time of setting new one,you can check for the conflict of newly set alarm time with previously set alarms from database and reject if it is found same.