android Wie starte ich eine Aktivität, wenn der Benutzer auf eine Benachrichtigung klickt?

Ich möchte die Aktivität öffnen, wenn der Benutzer auf eine Benachrichtigung klickt. Ich weiß, dass diese Frage doppelt gestellt ist, aber ich konnte hier keine Lösung finden, was ich getan habe

NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!");

Intent resultIntent = new Intent(this, ResultActivity.class);

// Because clicking the notification opens a new ("special") activity, there's
// no need to create an artificial back stack.
PendingIntent resultPendingIntent =
    PendingIntent.getActivity(
    this,
    0,
    resultIntent,
    PendingIntent.FLAG_UPDATE_CURRENT
);

mBuilder.setContentIntent(resultPendingIntent);
// Sets an ID for the notification
int mNotificationId = 001;
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr = 
    (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(mNotificationId, mBuilder.build());

Hier istDokumentatio ich folgte. Hat jemand eine Idee? Warum konnte ResultActivity nicht geöffnet werden?

Antworten auf die Frage(8)

Ihre Antwort auf die Frage