zuerst sollten wir die Mitteilung erstellen, die eine Tätigkeit nennen:
Intent intent = new Intent(this, YourClass.class);
intent.putExtra("NotiClick",true);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
Notification Noti;
Noti = new Notification.Builder(this)
.setContentTitle("YourTitle")
.setContentText("YourDescription")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pIntent)
.setAutoCancel(true).build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, Noti);
}
Dann in dem onCreate() Ihre Klasse dies zu tun:
Bundle extras = getIntent().getExtras();
if(extras == null)
{
//not being clicked on
}
else if (extras.getBoolean("NotiClick"))
{
//being clicked
}
und für vollständig Schließen Sie die Anwendung können Sie töten Prozess:
android.os.Process.killProcess(android.os.Process.myPid());
Mögliche duplica te von [Benachrichtigungsleiste klicken, um App zu schließen] (https://stackoverflow.com/questions/9222406/notification-bar-click-to-close-app) –