title: Perform Action On Button Click in Custom Notification : Android
body: <p>I am trying to perform some action like pause music , play music on button click of a custom notification in android.
  Currently I am doing it in this way , </p>
  
  <pre><code>    int icon = R.drawable.ic_launcher;
      long when = System.currentTimeMillis();
      Notification notification = new Notification(icon, "Custom Notification", when);
  
      NotificationManager mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
  
      RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.layout);
      contentView.setTextViewText(R.id.textView1, "Custom notification");
      contentView.setOnClickPendingIntent(R.id.button1, pIntent);
      notification.contentView = contentView;
  
      Intent notificationIntent = new Intent(this, MainActivity.class);
      PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
      notification.contentIntent = contentIntent;
  
      notification.flags |= Notification.FLAG_NO_CLEAR; //Do not clear the notification
      notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
      notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration
      notification.defaults |= Notification.DEFAULT_SOUND; // Sound
  
      mNotificationManager.notify(1, notification);
  </code></pre>
  
  <p>But this one takes me to another activity.
  Is there anyway to implement notification action on the same activity. </p>
  
  <p>for example.. let's say i raise a notifcation, and when the user press on it, then instead of take me to some activity, it invoke some regular method in my current activity/service</p>