android– 向PendingIntent添加标志

android– 向PendingIntent添加标志,第1张

概述当我们将0作为标志传递给PendingIntent时,如下所示:PendingIntentpi=PendingIntent.getActivity(this,1,i,0);它是否遵循任何标志规则意味着默认情况下0对应于任何标志.如果我们创建另一个PendingIntent为PendingIntentpii=PendingIntent.getActivity(this,1,i,0);

当我们将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);

根据文档,如果存在existign对象,PendingIntent.FLAG_NO_CREATE不会创建任何新对象.
我在NotifResult活动中打印数字的值,其中数字值将是80而不是50,因为它应该使用具有旧值的现有意图(根据我的理解).明确更新为什么输出将来80.
日志显示对象与预期相同.

谢谢

解决方法:

你打电话的时候:

PendingIntent pi=PendingIntent.getActivity(this, 1, i, 0);

传递0作为flags参数意味着您没有设置标志.

如果你打电话:

PendingIntent pii=PendingIntent.getActivity(this, 1, i, 0);

再次,你传递的Intent与第一次调用的Intent匹配,然后你将获得与第一次调用相同的PendingIntent. “匹配”表示动作,数据,类别和组件都是相同的.匹配时不考虑额外的内容.

如果您在第二次调用的Intent中提供了不同的额外内容,那么在发送时PendingIntent中不会出现这些额外内容.将使用第一次调用的Intent中的额外内容.

我无法解释你所看到的关于“50”和“80”的行为.根据文档和我的理解,根据我自己的观察,你应该看到“50”而不是“80”.必须有其他奇怪的事情发生.你在真实设备上测试吗?一个模拟器?什么版本的AndroID?

总结

以上是内存溢出为你收集整理的android – 向PendingIntent添加标志全部内容,希望文章能够帮你解决android – 向PendingIntent添加标志所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1110706.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存