通知仅在KitKat上打开错误的活动

时间:2014-01-19 22:11:09

标签: android android-4.4-kitkat

以下代码在Jelly Bean上正常运行 - 通知打开TimerActivity。 但是在KitKat上,此代码会打开MainActivity。这是一个错误吗?

mBuilder = new NotificationCompat.Builder(getApplicationContext())
    .setSmallIcon(ongoingNotificationIcon)
    .setContentTitle(ongoingNotificationContentTitle)
    .setContentText(ongoingNotificationContentText)
    .setTicker(ongoingNotificationTicker)
    .setPriority(99)
    .setOngoing(true)
    ;

Intent resultIntent = new Intent(this, TimerActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(TimerActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
mBuilder.setContentIntent(resultPendingIntent);
timerNotification = mBuilder.build();
startForeground(NOTIFICATION_ID, timerNotification);

1 个答案:

答案 0 :(得分:5)

这与此处的问题类似:

http://code.google.com/p/android/issues/detail?id=61850

http://code.google.com/p/android/issues/detail?id=63236

建议的解决方法是取消现有的待处理意图或使用 PendingIntent.FLAG_CANCEL_CURRENT