title: How to stop service from its own foreground notification
body: <p>I have a <code>Service</code> running. and in its <code>onStartCommand</code> I am doing <code>startforeground</code> to avoid killing by system.</p>
  
  <pre><code>public int onStartCommand(Intent intent, int flags, int startId) {
      if (ACTION_STOP_SERVICE.equals(intent.getAction())) {
          Log.d(TAG,"called to cancel service");
          manager.cancel(NOTIFCATION_ID);
          stopSelf();
      }
      NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
      builder.setContentTitle("abc");
      builder.setContentText("Press below button to stoP.");
      builder.setPriority(NotificationCompat.PRIORITY_HIGH);
      builder.setSmallIcon(R.drawable.ic_launcher);
  
      Intent stopSelf = new Intent(this, SameService.class);
      stopSelf.setAction(this.ACTION_STOP_SERVICE);
      PendingIntent pStopSelf = PendingIntent.getService(this, 0, stopSelf,0);
      builder.addAction(R.drawable.ic_launcher, "Stop", pStopSelf);
      manager.notify(NOTIFCATION_ID, builder.build());
  }
  </code></pre>
  
  <p>but after pressing button , <code>PendingIntent</code> is not working and my <code>activity</code> is not getting stopped by it.</p>
  
  <p>Can someone please tell, what wrong am I doing here or any other solution to stop service from the foreground <code>notification</code> made by self.</p>
  
  <p>Thanks</p>