2

I am new to android programming. I am developing an app which has a local notification. I am using Alarmmanager to set a local notification. When I set the same time to Alarmmanager onReceive is called once for that time. My pending intent is also different.

Here how I am setting alarm:

for(int i = 0; i < dosageDtoList.size();i++)
{
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    DosageDto dosageDto = dosageDtoList.get(i);

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");

    String time = dosageDto.getReminderTime();
    String dateTime = startDateStr + " " + time;
    Date formattedDate = simpleDateFormat.parse(dateTime);                        

    Calendar cal = Calendar.getInstance();                        
    cal.setTime(formattedDate);

    Intent notificationIntent = new Intent("android.media.action.DISPLAY_NOTIFICATION");
    notificationIntent.addCategory("android.intent.category.DEFAULT");

    notificationIntent.putExtra(Constants.POS,i);                        
    notificationIntent.putExtra(Constants.END_DATE, endDateStr);                        
    notificationIntent.putExtra(Constants.TITLE, userDrugDto.getUserName());                        
    notificationIntent.putExtra(Constants.SUB_TITLE, userDrugDto.getDrugName());

    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                                    Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent broadcast = PendingIntent.getBroadcast(context, i, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    if(alarmManager != null)
     { 
       alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY, broadcast);
     }
}

Here is my Receiver class:

public class AlarmReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
      // generating notification 
    }
}

If I set an alarm for these two dates and time 1. 01-June-2018 15:10 2. 01-June-2018 15:10

With different pending intent ideally onReceive should be called twice but it getting called once.

Am I missing something?

Thankless
  • 129
  • 2
  • 8

0 Answers0