Search code examples
androidandroid-alarms

Multiple alarm in android


I am having a reminder application in which i have an alarm manager like this

public class ReminderManager {

private Context mContext; 
private AlarmManager mAlarmManager;

public ReminderManager(Context context) {
    mContext = context; 
    mAlarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
}

public void setReminder(Long taskId, Calendar when) {
     System.out.println("**********************************remindedrmanager************************" );

    Intent i = new Intent(mContext, OnAlarmReceiver.class);
    i.putExtra(RemindersDbAdapter.KEY_ROWID, (long)taskId); 

    PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, i, PendingIntent.FLAG_ONE_SHOT); 

    mAlarmManager.set(AlarmManager.RTC_WAKEUP, when.getTimeInMillis(), pi);
}
}

I am getting only one alram even if I set multiple alarm. Is the problem due to some mistake in the above code or is it because of some other mistake.


Solution

  • You have change argument no 2 in line where you declared pending Intent as per below code. Instead specify (int)System.currentTimeMillis() in place of 0

    And also android set multiple alarms simultaneosuly

    PendingIntent pi = PendingIntent.getBroadcast(mContext,(int)System.currentTimeMillis(), i, PendingIntent.FLAG_UPDATE_CURRENT);