【发布时间】:2014-09-11 16:42:45
【问题描述】:
当我们将 0 作为标志传递给 PendingIntent 时,如下所示:
PendingIntent pi=PendingIntent.getActivity(this, 1, i, 0);
它是否遵循任何标志规则意味着 0 默认对应于任何标志。
如果我们创建另一个 PendingIntent 为
PendingIntent pii=PendingIntent.getActivity(this, 1, i, 0);
它会和之前一样吗?如果我对 Intent 中的数据进行任何更改,它现在会对应于 Intent 中的新数据还是仍然有旧数据。
我面临的另一个问题是 我正在尝试检查标志
PendingIntent.FLAG_NO_CREATE
我写了以下代码:
Intent i=new Intent(this,NotifResult.class);
i.putExtra("number",50);
PendingIntent pi=PendingIntent.getActivity(this, 1, i, 0);
NotificationCompat.Builder nb=new NotificationCompat.Builder(this);
nb.setSmallIcon(R.drawable.ic_launcher);
nb.setTicker("ticker is here");
nb.setWhen(System.currentTimeMillis())
.setContentTitle("just the title")
.setContentText("and the description")
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setContentIntent(pi);
Notification notif=nb.build();
NotificationManager nm=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(11, notif);
i.putExtra("number",80);
PendingIntent pisecond=PendingIntent.getActivity(this, 1, i, PendingIntent.FLAG_NO_CREATE);
if(pi.equals(pisecond))
Log.v("check","they are equal");
else
Log.v("check", "they are not equal");
notif.contentIntent=pisecond;
nm.notify(11, notif);
根据文档,如果存在存在对象,则 PendingIntent.FLAG_NO_CREATE 不会创建任何新对象。 我在 NotifResult 活动中打印数字值,其中数字值将变为 80 而不是预期的 50,因为它应该使用具有旧值的现有意图(根据我的理解)。请更新输出为 80 的原因。 日志显示对象与预期相同。
谢谢
【问题讨论】:
标签: android android-pendingintent