简体   繁体   中英

when i click notification open another my application

when i'm in my application,i click my application's notification open another my application,there are two same application on screen and btw i'm create notification from intent service

private void sendNotification(String msg, int msgdifferent) {
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle("......")
                    .setContentText(msg).setContentInfo(msgdifferent + "");
    Intent resultIntent = new Intent(this, MainActivity.class);
    resultIntent.putExtra("Update", "YES");
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
 PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
 mBuilder.setContentIntent(resultPendingIntent);
 NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

You mean every notification open new activity. So i think you forgot to add this steps as referred from documentation

    android:excludeFromRecents="true"
    android:launchMode="singleTask"
    android:taskAffinity=""

and also set your resultIntent flags like

resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM