title: How to make notification uncancellable/unremovable
body: <p>I want to make my Android notification stay even if user clicks it or clicks clear all...</p>
  
  <p>Right now it stays sometimes, and gets removed sometimes, and I'm not sure what causes it.</p>
  
  <p>Here's my code for the notification:</p>
  
  <pre><code>@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  public static void createNotification()
  {
      NotificationManager notificationManager = (NotificationManager)context.getSystemService(NOTIFICATION_SERVICE);
  
      NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                              .setContentTitle("Wolftech Field Agent")
                              .setContentText("Getting Status")
                              .setSmallIcon(R.drawable.ic_launcher)
                              .setOngoing(true)
                              .setAutoCancel(false);
  
      Intent intent = new Intent(context, FieldAgent.class);
      intent.setAction(Intent.ACTION_MAIN);
      intent.addCategory(Intent.CATEGORY_LAUNCHER);
  
      TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
      stackBuilder.addParentStack(FieldAgent.class);
      stackBuilder.addNextIntent(intent);
  
      PendingIntent pendingIntent = stackBuilder.getPendingIntent(0,  PendingIntent.FLAG_UPDATE_CURRENT);
  
      builder.setContentIntent(pendingIntent);
  
      notificationManager.notify(NOTIFICATION_ID, builder.build());
  }
  
  public static void updateNotificationText(String inString)
  {
      NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
  
      NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                                              .setContentText(inString)
                                              .setContentTitle("Wolftech Field Agent")
                                              .setSmallIcon(R.drawable.ic_launcher)
                                              .setOngoing(true)
                                              .setAutoCancel(false);
  
      Intent intent = new Intent(context, FieldAgent.class);
      intent.setAction(Intent.ACTION_MAIN);
      intent.addCategory(Intent.CATEGORY_LAUNCHER);
  
      TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
      stackBuilder.addParentStack(FieldAgent.class);
      stackBuilder.addNextIntent(intent);
  
      PendingIntent pendingIntent = stackBuilder.getPendingIntent(0,  PendingIntent.FLAG_UPDATE_CURRENT);
  
      builder.setContentIntent(pendingIntent);
  
      notificationManager.notify(NOTIFICATION_ID, builder.build());
  }
  
  public static void cancelNotification()
  {
      NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
  
      notificationManager.cancel(NOTIFICATION_ID);
  }
  </code></pre>