1

Is Possible to clearAll notification?

btnMessageStyle1.setOnClickListener
           (arg0 -> {

         final int NOTIFICATION_ID = 1;
            mNotifyManager =
                    (NotificationManager) 
             getSystemService(Context.NOTIFICATION_SERVICE);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
               //                makeNotificationChannel("CHANNEL_1", "Example 
           channel", 
             NotificationManager.IMPORTANCE_DEFAULT);
                NotificationChannel channel = new 
              NotificationChannel("CHANNEL_1",
                        "Channel human readable title",
                        NotificationManager.IMPORTANCE_DEFAULT);
                mNotifyManager.createNotificationChannel(channel);
            }
            build = new NotificationCompat.Builder(getApplicationContext(), "CHANNEL_1");
            build.setContentTitle("Download")
                    .setContentText("Download in progress")
                    .setOngoing(true)
                    .setSmallIcon(R.drawable.jd)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(),
                            R.mipmap.ic_launcher))
                    .setAutoCancel(true)
//                        .setContentIntent(resultPendingIntent)
                    .setPriority(NotificationCompat.PRIORITY_HIGH)
                    .setWhen(System.currentTimeMillis());

            mNotifyManager.notify(NOTIFICATION_ID, build.build());

                new Download().execute();
        });
    }

I try to cancel all the Notifications:

@Override
    public void onDestroy() {
       mNotifyManager.cancelAll();
        super.onDestroy();

    }

This question How to clear a notification in Android Solution does not work my application

  • 1
    This is not Related above duplicate Question. – S_i_l_e_n_t C_o_d_e_r May 07 '19 at 05:51
  • It it related . And `onDestroy()` is not meant to call each time . Read [This thread throughout](https://stackoverflow.com/questions/18361719/android-activity-ondestroy-is-not-always-called-and-if-called-only-part-of-the). – ADM May 07 '19 at 05:56
  • Put a log on `onDestroy` and see when and how much `onDestroy` called? if this `onDestroy` belongs to a service, it's possible that something stays awake service and `onDestroy` never had called – SamiAzar May 07 '19 at 06:00
  • 1
    Not working NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(NOTIFICATION_ID); – S_i_l_e_n_t C_o_d_e_r May 07 '19 at 06:17

0 Answers0