title: Execute an action on notification click
body: <p>I have an application which uses a persistent notification within a service and runs in the background. While this service is running, I need to be able to call a method/do some action when the notification is clicked. However, I'm not sure how to implement this. <strong>I have read through many similar questions/answers, however none were answered clearly or suitably to my purposes.</strong> <a href="https://stackoverflow.com/questions/11270898/how-to-execute-a-method-by-clicking-a-notification">This</a> SO questions comes close to what I am trying to achieve, but the chosen answer is hard to understand.</p>
  
  <p>My service/notification is started in the onCreate() method for my BackgroundService class...</p>
  
  <pre><code>Notification notification = new Notification();
      startForeground(1, notification);
      registerReceiver(receiver, filter);
  </code></pre>
  
  <p>and this service is launched from my main activity's button click:</p>
  
  <pre><code>final Intent service = new Intent(Main.this, BackgroundService.class);
  
  bStart.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              if((counter % 2) == 0){
  
                  bStart.setText("STOP");
                  startService(service);
  
              }else {
                  bStart.setText("BEGIN");
                  stopService(service);
              }
  
              counter++;
  
          }
  </code></pre>
  
  <p>any advice is appreciated</p>