title: Stopping IntentService by clicking Notification
body: <p>I'm doing some background work in an IntentService and trying to make it stop by clicking a notification. For stopping the work I have a static method, that sets a flag.</p>
  
  <pre><code>public static void stopService() {
      if (task != null) {
          task.setCancelFlag(true);
      }
  }
  </code></pre>
  
  <p>The notification has a <code>PendingIntent</code>, that sends a Broadcast to a Receiver, that attempts to stop the service.</p>
  
  <pre><code>Intent intent = new Intent(this, AlarmReceiver.class);
  intent.setAction(AlarmReceiver.STOP_SERVICE);
  
  PendingIntent contentIntent = PendingIntent.getBroadcast(getBaseContext(), 0,
                  intent, 0);
  
  notification.contentIntent = contentIntent;
  </code></pre>
  
  <p>The Receiver calls the <code>stopService()</code> method when it receives a broadcast.</p>
  
  <pre><code>if (intent.getAction().equals(STOP_SERVICE)) {
      UpdateCheckService.stopService();
  }
  </code></pre>
  
  <p>Strangely enough, the <code>stopService()</code> method is not called properly. If I try to log it, the part with the flag setting is not executed. Even if I set a breakpoint on the Receiver and try to debug it, it doesn't work.</p>
  
  <p>However, if I call the same method from an <code>Activity</code> by clicking a button, everything works as intended.</p>
  
  <p>Does somebody know, where this strange behavior comes from?</p>