title: App crashes due to bad notification for startforeground
body: <p>i have been working on night filter app but i stuck with sdk version. My app is perfectly working on device whose sdk version is less then 23 but above 23 is not working it's like when i tested my app in my Xiaomi which has android 9 app crashes and when i track the logcat error will through stating Bad Notification For StartForeGround. see this logcat message</p>
  <pre><code>2021-01-05 13:24:04.295 17312-17312/delhisehai.eyecare E/AndroidRuntime: FATAL EXCEPTION: main
      Process: delhisehai.eyecare, PID: 17312
      android.app.RemoteServiceException: Bad notification for startForeground
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1760)
          at android.os.Handler.dispatchMessage(Handler.java:106)
          at android.os.Looper.loop(Looper.java:201)
          at android.app.ActivityThread.main(ActivityThread.java:6823)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
  </code></pre>
  <p>This is my <strong>Service</strong> activity</p>
  <pre><code>private void updateNotification() {
          Intent intent = new Intent((Context)this, MyBroadcastReceiver.class);
          intent.setAction(&quot;ACTION_SWTICH_FILTER&quot;);
          PendingIntent pendingIntent = PendingIntent.getBroadcast((Context)this, (int)0, (Intent)intent, (int)0);
          Intent intent2 = new Intent((Context)this, MyBroadcastReceiver.class);
          intent2.setAction(&quot;ADJUST_INTENSITY&quot;);
          intent2.putExtra(&quot;intensity&quot;, &quot;add&quot;);
          PendingIntent pendingIntent2 = PendingIntent.getBroadcast((Context)this, (int)1, (Intent)intent2, PendingIntent.FLAG_UPDATE_CURRENT);
          Intent intent3 = new Intent((Context)this, MyBroadcastReceiver.class);
          intent3.setAction(&quot;ADJUST_INTENSITY&quot;);
          intent3.putExtra(&quot;intensity&quot;, &quot;minus&quot;);
          PendingIntent pendingIntent3 = PendingIntent.getBroadcast((Context)this, (int)2, (Intent)intent3, PendingIntent.FLAG_UPDATE_CURRENT);
          PendingIntent pendingIntent4 = PendingIntent.getActivity((Context)this, (int)0, (Intent)new Intent((Context)this, MainActivity.class), (int)0);
          String string2 = getResources().getString(R.string.app_name);
          int n = MySharedPreferences.getAlpha((Context)this);
          RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.layout_notification);
          remoteViews.setTextViewText(R.id.notitext1, (CharSequence)string2);
          remoteViews.setTextViewText(R.id.notitext4, (CharSequence)((int)(100.0 * (double)n / 200.0) + &quot;%&quot;));
          remoteViews.setOnClickPendingIntent(R.id.btn1, pendingIntent);
          remoteViews.setOnClickPendingIntent(R.id.btn2, pendingIntent);
          remoteViews.setOnClickPendingIntent(R.id.notitext3, pendingIntent2);
          remoteViews.setOnClickPendingIntent(R.id.notitext45, pendingIntent3);
          if (filterIsOn) {
              remoteViews.setViewVisibility(R.id.notitext2, View.INVISIBLE);
              remoteViews.setViewVisibility(R.id.notilayout, View.VISIBLE);
              remoteViews.setViewVisibility(R.id.btn2, View.INVISIBLE);
              remoteViews.setViewVisibility(R.id.btn1, View.VISIBLE);
              remoteViews.setTextViewText(R.id.btn1, (CharSequence)this.getResources().getString(R.string.turn_on));
          } else {
              remoteViews.setViewVisibility(R.id.notitext2, View.VISIBLE);
              remoteViews.setViewVisibility(R.id.notilayout, View.INVISIBLE);
              remoteViews.setViewVisibility(R.id.btn2,  View.VISIBLE);
              remoteViews.setViewVisibility(R.id.btn1, View.INVISIBLE);
              remoteViews.setTextViewText(R.id.btn2, (CharSequence)this.getResources().getString(R.string.turn_off));
          }
          Notification notification = new NotificationCompat.Builder(getApplicationContext()).setOngoing(false).setSmallIcon(R.drawable.red1).setContentIntent(pendingIntent4).setPriority(2).setWhen(0L).setContent(remoteViews).build();
          if (!MySharedPreferences.getShowIcon((Context)this)) {
              notification = new NotificationCompat.Builder(getApplicationContext()).setOngoing(false).setSmallIcon(R.drawable.red1).setContentIntent(pendingIntent4).setPriority(-2).setWhen(0L).setContent(remoteViews).build();
          }
          startForeground(9216, notification);
      }
  </code></pre>
  <p>I have using remoteviews to show notification and manipulate there only like music player but the problem is how to tacke this bug. I also use startforeground permission in manifest but same problem app crash. I think there is problem in <strong>Notification ID</strong> which i set to 9216. so can anyone give me solution for same.</p>
  <p>Thanks in Advance!</p>