开发者

Activity fails to update on intent receive

The following code gives the same content after I send two notifications with different content say Content1 and Content2. The resulting activity always shows only Content2. What could be the reason for it?

public void onReceive(Context context, Intent intent) {
    abortBroadcast();

    mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    int icon = R.drawable.icon;
    CharSequence tickerText = intent.getStringExtra("NOTIFICATION_TITLE");
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    CharSequence contentTitle = intent.getStringExtra("NOTIFICATION_TITLE");
    CharSequence contentText = intent.getStringExtra("NOTIFICATION_DETAILS");
    Intent notificationIntent = new Intent(context,CustomActivity.class);
    notificationIntent.putExtra("TITLE", contentTitle);
    notificationIntent.putExtra("DETAILS", contentText);
    //notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    PendingIntent contentI开发者_JAVA百科ntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    mNotificationManager.notify(notifUUID.hashCode(), notification);


}


Got the answer! the fix was simple - just added: notificationIntent.setAction(String.valueOf(notifUUID.hashCode()));

Any unique value (timestamp would have worked too) set as the intent action would work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜