Уведомление по расписанию Android Удалить / Отменить Не работает - PullRequest
0 голосов
/ 07 июня 2019

Привет, разработчик. Я хочу отменить уведомление, но отменить уведомление, не работающее в программе 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();
            }}});
...