I am trying to run an explicit intent to set multiple alarms at different times.
I am trying to do this from a CustomAdapter.
I have an onclicklister on a button . The alarm is getting set for only the first value in ArrayList . Then even though the loop is running for all the elements of arraylist . The alarms are not added .
Here is my button on click method
currentItemView.findViewById(R.id.alarm_btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MedicineRecordHandler mrd=arrayList.get(position);
for(String i:mrd.getReminder()){
int hour=Integer.parseInt(i.substring(0,2));
int min=Integer.parseInt(i.substring(2,4));
createAlarm(mrd.getName(),hour,min);
}
}
});
In the above code mrd.getReminder() returns a String type arrayList containing times like [ "0800" , "1400","2030" ]
and here is my create alarm method
public void createAlarm(String message, int hour, int minutes) {
Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM)
.putExtra(AlarmClock.EXTRA_MESSAGE, message)
.putExtra(AlarmClock.EXTRA_HOUR, hour)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(AlarmClock.EXTRA_MINUTES, minutes)
.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
getContext().startActivity(intent);
}