ich bin mit dieser Lösung: How to make notification intent resume rather than making a new intent?klicken Sie auf Benachrichtigung aktuelle Aktivität zu gehen
I funktioniert gut, wenn ich meine app normal laufen .. aber meine app hat eine Share-Funktion.
Wenn ich die Bilder, die ich aus der Galerie App freigeben möchte, auswähle und sie in meiner Aktivität öffne, erstelle ich eine Benachrichtigung in der Aktivität. Ich möchte, dass, wenn Benutzer auf die Benachrichtigung klickt, öffnet die vorhandene Aktivität (geöffnet von der Galerie App)
Das Problem ist, dass, wenn ich auf die Benachrichtigung klicken Sie nicht diese Aktivität fortsetzen, sondern stattdessen eine neue Instanz der Aktivität oder eine andere Instanz bereits geöffnet zuvor
Edit: Mehr Erklärung
Meine app heißt ShareApp und die Aktivität genannt wird Teilen das Problem ist, dass, wenn ich öffnen Sie die Teilen über Galerie App, eine Instanz der ShareActivity wird an der Spitze der Gal erstellt lery app task's stack. Nun, wenn ich eine Meldung erstellen, die auf meine Teile Punkte, verwende ich die Absicht:
Intent intent = new Intent(this, ShareActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Problem ist, dass, wenn ich auf der Meldung klicken, es verweist auf die Instanz des Teils es in der Stack der ShareApp Aufgabe statt die gallery app task's stack ..
eine idee wie man auf den richtigen task-stapel zeigt ??
bearbeiten 2: mein Code
int defaults = Notification.FLAG_NO_CLEAR;
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(getString(R.string.app_name))
.setContentText(text)
.setDefaults(defaults);
Intent intent = new Intent(this, this.getClass());
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
mBuilder.setContentIntent(pendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(_ID, mBuilder.build());
bearbeiten 3: adb shell dumpsys Aktivität (nach dem Code von David https://stackoverflow.com/a/16901603/1334268 Anwendung)
Meine App ist shareApp und meine Tätigkeit genannt wird ShareActivity
Bevor Sie auf Benachrichtigung klicken:
Main stack:
TaskRecord{41965708 #6 A com.android.gallery3d}
Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.gallery3d/.app.Gallery bnds=[364,50][108,108]}
Hist #2: ActivityRecord{417ccc28 com.yeahman.shareapp/.ShareActivity}
Intent { act=android.intent.action.SEND_MULTIPLE typ=image/* cmp=com.yeahman.shareapp/.ShareActivity (has extras) }
ProcessRecord{41c868d0 6088:com.yeahman.shareapp/10116}
Hist #1: ActivityRecord{4135e540 com.android.gallery3d/.app.Gallery}
Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.gallery3d/.app.Gallery bnds=[364,50][108,108] }
Nach einem Klick-Benachrichtigung:
Main stack:
TaskRecord{41965708 #6 A com.android.gallery3d}
Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.gallery3d/.app.Gallery bnds=[364,50][108,108]}
Hist #3: ActivityRecord{4169f358 com.android.gallery3d/.app.Gallery}
Intent { flg=0x20000000 cmp=com.android.gallery3d/.app.Gallery bnds=[0,205][480,301] }
ProcessRecord{4175dd28 5808:com.android.gallery3d/10036}
Hist #2: ActivityRecord{417ccc28 com.yeahman.shareapp/.ShareActivity}
Intent { act=android.intent.action.SEND_MULTIPLE typ=image/* cmp=com.yeahman.shareapp/.ShareActivity (has extras) }
ProcessRecord{41c868d0 6088:com.yeahman.shareapp/10116}
Hist #1: ActivityRecord{4135e540 com.android.gallery3d/.app.Gallery}
Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.gallery3d/.app.Gallery bnds=[364,50][108,108] }
Geben Sie den Code ein, mit dem Sie den 'Intent',' PendingIntent' und den 'Notification' erstellen. –
ich habe gerade meine Frage mit meinem Code bearbeitet – yeahman
gibt es eine Lösung? Ich werde akzeptieren, es ist nicht möglich, als Antwort mit Backup-Erklärung – yeahman