title: Can not dismiss notification of service created
body: <p>I've created a service , And I also created a notification so when my service runs there is a notification for it.
  Now , I want users to be able to swipe/dismiss the notification but when trying to do so I've encountered two problems:</p>
  
  <pre><code>@Override
  public int onStartCommand(Intent intent, int flags, int startId) {
  
          password = intent.getStringExtra("password");
          number = intent.getStringExtra("number");
  
  
      Intent activityIntent = new Intent(this, MainActivity.class);
      PendingIntent pendingIntent =   PendingIntent.getActivity(getApplicationContext(), 0,
              activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  
  
      Notification notification = new Notification.Builder(this).
              setContentTitle(getText(R.string.app_name)).
              setContentText("Subject").
              setContentInfo("Doing stuff in the background...").
              setSmallIcon(R.drawable.ic).
              setAutoCancel(true).
              setContentIntent(pendingIntent).build();
  
      startForeground(1, notification);
  
  
      return super.onStartCommand(intent, flags, startId);
  }
  </code></pre>
  
  <p>This code worked perfectly , the only problem with this code is that users cannot swipe dismiss the notification , So from searching around I found that I can fix it by replacing 'startForeground' function with </p>
  
  <pre><code>    NotificationManager notificationManager =
              (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
      notificationManager.notify(0,notification);
  </code></pre>
  
  <p>And then it worked, I can swipe dismiss, But now I get a different problem , Once I close my application (using long press on middle button then close all applications)
  My app thrrows a nullpointerexception few moments later pointing to the line :</p>
  
  <pre><code>  password = intent.getStringExtra("password");
  </code></pre>
  
  <p>as if the intent is null. This does not happen when I use the startForeground function</p>
  
  <p>What might be the problem ?</p>