In Android.O the old builder

NotificationCompat.Builder(Context context) 

declared obsolete.

Now you need to specify the second parameter

 NotificationCompat.Builder(Context context, String channelId) 

In principle, quite a lot on the Internet about what it is and what it is eaten with, but, in all examples, this very NotificationChannel is created exactly before calling NotificationCompat.Builder

Actually a question. Is it really normal, before creating each new notification to create a channel for it, or does it still work somehow differently? Common sense dictates that creating a channel is logical only once and using the entire lifetime of the application, no?

Can you give links to a competent article on this issue?

PS Official documentation . READ STRICTLY IN THE ENGLISH LANGUAGE! Russian version of the page is very outdated.

  • one
  • @YuraIvanov in the Russian version of the old dock, without a description of the channels, and the button to change the language still need to search. I did not expect from Google ... - rjhdby

1 answer 1

I have it implemented, I create it once

  if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel notificationChannel = notificationManager.getNotificationChannel(CHANNEL_ID); if (notificationChannel == null) { int importance = NotificationManager.IMPORTANCE_HIGH; notificationChannel = new NotificationChannel(CHANNEL_ID, "Имя канала", importance); notificationChannel.setLightColor(Color.GREEN); notificationChannel.enableVibration(true); notificationManager.createNotificationChannel(notificationChannel); } }