Search code examples
androidandroid-alarmsandroid-broadcast

Not able to Set Multiple Reminders


There is functionality in my app where a user can set multiple reminders. But the problem is that when user set time for reminder A and than for Reminder B, then reminder B only gets call. That is the intent for reminder A never gets call. In short Only one reminder is working all the time. Here is snippet of setting reminder and calling Broadcast.

public void setAlarm(int dayValue, int monthValue, int yearValue, int hourValue, int minValue, String message, int pos){

            int ID = 1;
        calendar.set(yearValue, monthValue, dayValue, hourValue, minValue, 0);
        Calendar tempCal = Calendar.getInstance();
        Intent intent = new Intent(context,ReminderNissan.class);

        intent.putExtra("title",message);
        intent.putExtra("note",message);
        intent.putExtra("id", pos);

        Log.d("****Indide set alarm method*****", "PSOITION " + pos);

        if((tempCal.compareTo(calendar)==  -1) || (tempCal.compareTo(calendar)==  0)){
            try{
                db.open();
                db.setAlarm(id.get(pos).toString(), 1);
                db.close();
            }catch(SQLException exp){
                Log.d("SET ALARM OFF SQL EXCEPTION", exp.toString());
            }

            PendingIntent sender = PendingIntent.getBroadcast(context, ID,intent,0);

            am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
            //Toast.makeText(context, "*** ALARM SET AT ***  " + pos, Toast.LENGTH_SHORT).show();

        }else{
            try{
                db.open();
                db.setAlarm(id.get(pos).toString(), 0);
                db.close();
            }catch(SQLException exp){
                Log.d("SET ALARM OFF SQL EXCEPTION", exp.toString());
            }
            Toast.makeText(context, "Time Has Alredy Passed. Set proper Time. ", Toast.LENGTH_SHORT).show();
        }
    }

Solution

  • I'm not entirely sure but it could be that you are overriding the alerts.

    PendingIntent sender = PendingIntent.getBroadcast(context, ID,intent,0);
    

    the ID argument is always 1 in your case. Just make it an unique id and it should be fine fine.