嘿,我想取消通知,但取消通知在recyclerview中不起作用。我知道我的代码中有什么问题,但是我听不到。请告诉我解决方案.. 这是我的警报启动代码。
private void AlarmSet() {
randomkey = (int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(Task_Notification.this, Notify_Broadcast.class);
intent.putExtra("rrrr", value);
PendingIntent pendingIntent = PendingIntent.getBroadcast(Task_Notification.this,randomkey, intent, 0);
alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}
在Recyclerview中显示我的取消通知代码
holder.dlt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
int randomkey = Integer.parseInt(taskresult.get(position).getTime());
AlarmManager alarmManager=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent =new Intent(context,Notify_Broadcast.class);
intent.putExtra("rrrr",taskresult.get(position).getTask1());
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,randomkey,intent,PendingIntent.FLAG_CANCEL_CURRENT);
alarmManager.cancel(pendingIntent);
realm = Realm.getDefaultInstance();
realm.beginTransaction();
taskresult.get(position).deleteFromRealm();
notifyDataSetChanged();
realm.commitTransaction();
Toast.makeText(context, "Task data deleted", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
}}});