【发布时间】:2017-02-28 23:49:09
【问题描述】:
通知提供旧值。 我阅读了 stackoverflow 链接,但仍然无法为我工作: Notification passes old Intent Extras
我有一个活动 A。 当我在活动 B 上并触摸通知时,正确给出了 Extra 参数并显示活动 A 以及使用 getExtras(..); 读取的正确值;
那么 Activity A 仍然在顶部 - 显示在屏幕上: 我单击带有新值 putExtras(newValue) 的 second 通知,以创建一个 new 活动 A,但具有新值。
问题: intent.getExtras()` 正在读取点击的第一个通知的 旧 值,而不是第二个通知给出的新值。
我做了很多挂起意图标志和顶部链接组合的组合,但应用程序仍然采用旧值(第一次触摸通知的值)用于第二次通知。我尝试了标志:PendingIntent.FLAG_UPDATE_CURRENT 来更新值,而不是创建一个新的 Activity 和其他一些标志。
当 Activity A 仍显示在屏幕上时,如何让第二个通知为 Activity A 提供正确的值?
创建通知的代码的 sn-p。
public void notificationCreateGu(String newMessageUserUidOfSender) {
Intent it = new Intent(this,ActivityA.class);
it.putExtra(USER_UID_READER,newMessageUserUidOfSender);
StoreValuesClass.count=StoreValuesClass.count+2;
PendingIntent pi = PendingIntent.getActivity(this, StoreValuesClass.count,it, 0);
Notification notification = new NotificationCompat.Builder(this)
.setTicker(newMessageUserUidOfSender )
.setSmallIcon(android.R.mipmap.sym_def_app_icon)
.setContentTitle("Title Message ")
.setContentText(String.valueOf(newMessageUserUidOfSender))
.setContentIntent(pi)
.setAutoCancel(true)
.build();
int m;
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
m= StoreValuesClass.count=StoreValuesClass.count+2;
notificationManager.notify((m), notification);
}
//StoreValueClass.count 是一个静态值,Activity 可以读取它来为通知提供唯一的 id。
读取值的代码的 sn-p。
userUidReader = getIntent().getExtras().getString(USER_UID_READER)
我尝试将值重新加载到 onResume() 中,但在 onResume() 中仍然采用第一次读取 getExtras() 时的旧值。 我知道操作系统Android不是创建一个新的Activity,而是把它交给顶部。
【问题讨论】:
标签: java android notifications