title: How to create notification when service is destroyed
body: <p>I am trying to create an ongoing notification which will appear when service is destroyed. When the user taps the notification the service is supposed to start again and the notification created when service is destroyed is supposed to disappear.
  Below is the code I am using </p>
  
  <pre><code>   private boolean mRunning;
  
          @Override
   public void onDestroy(){
  super.onDestroy();
  destroyed();
  Toast.makeText(getApplicationContext(),"you are offline",Toast.LENGTH_SHORT).show();
   }
  
   private void destroyed() {
  if (Build.VERSION.SDK_INT&gt;=Build.VERSION_CODES.O){
      String Notichanid="com.g.kupa";
      String channelname="My Background";
      NotificationChannel chan=new NotificationChannel(Notichanid,channelname,NotificationManager.IMPORTANCE_HIGH);
      chan.setLightColor(Color.BLUE);
      chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
      NotificationManager manager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
      assert manager!=null;
      manager.createNotificationChannel(chan);
      Intent notificationintnet=new Intent(this,Profile.class);
      notificationintnet.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      PendingIntent contentIntent=PendingIntent.getActivity(this,0,notificationintnet,0);
      NotificationCompat.Builder notificationBuilder=new NotificationCompat.Builder(this,Notichanid);
      Notification notification=notificationBuilder.setOngoing(false)
              .setSmallIcon(R.drawable.menu_icon)
              .setContentTitle("You are offline")
              .setContentText("If you are awaiting one of your bookings to be accepted, tap this notification to get back online")
              .setPriority(NotificationManager.IMPORTANCE_HIGH)
              .setCategory(Notification.CATEGORY_SERVICE)
              .setContentIntent(contentIntent)
              .build();
      manager.notify(19,notification);
  
      if (!mRunning){
          mRunning=true;
          manager.cancel(19);
      }
  </code></pre>
  
  <p>The last part of the code which features an if close is a new addition. Without the if notification the notification appears but when service is restarted it remains. 
  However now that I have added the if statement to remove the notification the notification is not even appearing when the service is destroyed, anyone to assist?</p>