当我点击通知打开另一个我的应用程序

时间:2014-09-25 18:08:31

标签: java android

当我在我的应用程序中时,我点击我的应用程序的通知打开另一个我的应用程序,屏幕上有两个相同的应用程序,顺便说一下我是从意图服务创建通知

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());
}

1 个答案:

答案 0 :(得分:0)

您的意思是每个通知都会打开新活动。所以我认为您忘记添加documentation

中提到的步骤
    android:excludeFromRecents="true"
    android:launchMode="singleTask"
    android:taskAffinity=""

并设置resultIntent标志,如

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