Is it possible to create multiple PendingIntents with the same requestCode and different extras?

后端 未结 2 640
北恋
北恋 2020-12-01 04:56

I\'m using AlarmManager to schedule anywhere between 1 and 35 alarms (depending on user input). When the user requests to schedule new alarms, I need to cancel

2条回答
  •  [愿得一人]
    2020-12-01 05:28

    Yes it is possible just put unique intent action for each alarm

    intent.setAction("uniqueCode");

    Intent intent = new Intent(context, MyAlarmReciver.class);
    intent.setAction("uniqueCode");
    PendingIntent pendingIntent = PendingIntent.getBroadcast(activity, 0,   intent, 0);
    AlarmManager alarmManager = (AlarmManager)       context.getSystemService(activity.ALARM_SERVICE);
    Calendar c = Calendar.getInstance();
    c.add(Calendar.MINUTE, 1);
    alarmManager.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(),   pendingIntent);
    

提交回复
热议问题