handling button click in notification <p>I have got a notification with one Button and I want to do something, when I click the button of the notification. </p> <p>Is there a possibility like <code>OnClickListener</code> to handle that?</p> <p>Here is the code for the notification: </p> <pre><code> private void notification_anzeigen(){ Intent intent = new Intent(this, GestureAnyWhere.class); // String notificationMessage = "GestureAnyWhere läuft im Hintergrund"; // intent.putExtra("NotificationMessage", notificationMessage); // intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); // build notification // the addAction re-use the same intent to keep the example short Notification n = new Notification.Builder(this) .setContentTitle("GestureAnyWhere läuft im Hintergrund") //.setContentText("GestureAnyWhere muss im Hintergrund ausgeführt werden, um Gesten zu erkennen") .setSmallIcon(R.drawable.ic_launcher) // muss rein, ansonsten wird keine Notifikation angezeigt .setContentIntent(pIntent) .addAction(R.drawable.ic_launcher, "Plus-Button", pIntent) .setStyle(new Notification.BigTextStyle().bigText("Auf den Plus-Button drücken, um auf aktueller Seite Gesten zu erkennen")) .setAutoCancel(true).build(); n.setLatestEventInfo(getApplicationContext(), "Plus-Button", "neu", pIntent); NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(0, n); } </code></pre> <p>Sorry that the question isn't clear. So I try to specifiy it a little bit better:</p> <ul> <li>I have got a background service which starts, when I minimize my application</li> <li>when the service is starting, a new notification will be shown to inform the user, that the application works in background now</li> <li>The background service shall be there in order to detect gestures, which are drawn outside the application </li> <li>When I click onto the notification and the application starts again, the service shall be stoped (otherwise I can draw inside my application and not click onto something anymore) -> so that is the first point I want to do: stop a background service, when I click onto the notification </li> <li>When I mimimize my application and start the service I am only able to draw onto the homescreen right now -> so that is the second point I want to do: when the user click onto a button under the notification an Activity shall be called in order that the user could draw on the current View</li> </ul> <p>Because I only want to know how a click onto a notification (or a Button under the notification) is handled in generally I don't provide the code for the service and all other stuff. </p> <p>I hope the question and what I want to do is a little bit clearer. </p> <p>Thanks a lot. </p>