【问题标题】:Android Pending intent started from notification doesn't replace the last从通知开始的 Android Pending Intent 不会替换最后一个
【发布时间】:2010-07-05 12:33:16
【问题描述】:

我已经阅读了许多关于同一主题的帖子,并尝试了所有给定的解决方案,但没有得到我想要的结果。 该程序应该从一个通知的附加内容开始一个意图:

NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);  

Intent notificationIntent = new Intent(context, myActivity.class);
    notificationIntent.putExtra("someData", data);

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

mNotificationManager.notify(ID, notification);

问题在于,当显示新通知时,添加到意图中的额外内容与第一个通知中的相同。我在意图和待定意图中都使用了不同的标志,但没有结果。我怎么了? 如果我只是用一个按钮启动相同的活动(和相同的附加功能),一切都会按预期进行。

【问题讨论】:

标签: android notifications android-pendingintent


【解决方案1】:

我不知道为什么我在让它工作时遇到这样的问题。我用来让它正常工作的标志组合是:

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 
                PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

我还删除了创建notificationIntent 时使用的所有标志。

【讨论】:

    【解决方案2】:

    尝试在AndroidManifest.xml文件中添加一个属性:

    <activity ... android:launchMode="singleTop"/>
    

    【讨论】:

      【解决方案3】:

      尝试为每个PendingIntent设置请求代码,它会起作用

      PendingIntent pendingIntent = PendingIntent.getActivity(this, RandomInt, intent,
                      PendingIntent.FLAG_ONE_SHOT);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-10-13
        • 1970-01-01
        • 1970-01-01
        • 2013-06-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多