Reputation: 419
i have a list view in which there are some toggle button (total 5) the functionality of the app is to set alrms for those dates which was clicked by user on toggle button checked i am sending data and and able to fetch data but didn't know what to do next i am able to make alarm ringing for single button but dont know how to set it for multiple dates the user can delete the alarms also here i am putting code pIndex is the index of button in list view
Intent intent = new Intent();
intent.setAction("action_d");
intent.putExtra("day",day);
intent.putExtra("month",month);
intent.putExtra("state",state);
intent.putExtra("count",mCount);
Log.v("pending intent",""+pIndex);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, pIndex, intent, 1);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),pendingIntent );
//on reciving class
final String action = arg1.getAction();
if ("action_d".equals(action)) {
// do function d
String day = arg1.getExtras().getString("day");
int cmonth =arg1.getExtras().getInt("month");
int state =arg1.getExtras().getInt("state");
int count =arg1.getExtras().getInt("count");
if(cmonth == month ){
Log.v("setting alarm for ","action d recived"+day);
if(day.equals(cDate))
{
vibrator.vibrate(2000);
notification.setLatestEventInfo(arg0, contentTitle, contentText, contentIntent);
//notification.defaults |= Notification.DEFAULT_SOUND;
notofManager.notify(NOTIF_ID,notification);
Intent mIntent = new Intent(arg0,DialogActivity.class); //Same as above two lines
mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
arg0.startActivity(mIntent);
}
}
}
Upvotes: 1
Views: 291
Reputation: 95568
You can set as many alarms as you want, the same way you are doing it now. You just need to make sure that each PendingIntent
that you pass to the AlarmManager
is unique. Unfortunately, the "extras" in the Intent
are ignored when trying to determine the uniqueness of PendingIntent
s. So you'll need to provide either a unique requestCode
or a unique ACTION in the Intent
to guarantee uniqueness of each PendingIntent
.
Upvotes: 2