Notification中PendingIntent的陷阱
来源:互联网 发布:snmpv3 java 编辑:程序博客网 时间:2024/04/29 22:42
最近做通知的时候用来发送多条通知的时候,发现当你创建多个Notification的时候,当你点击通知,通过PendingIntent以getBroadcast()调用Intent的时候,在BroadcastReceiver的onReceive()中得到intent中取得数据全是最后一条通知栏消息的,当然你设置的PendingIntent的flag有关,这样的根据通知栏的不同内容通过BroadcastReceiver的onReceive()执行不同的事件,就出现了混乱,这是个陷阱。。。
请谅解,讲的有点不易理解。。。
这里我们根据不同的action来实现,就可以达到多条Notification产生多个不同的onReceive()事件处理了,具体的就是
Intent intent = new Intent(action);intent.putExtra("data", data);PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);在onReceive()中通过intent.getAction()来判断唯一的Notification后,再用getStringExtra取值,前提是你先registerReceiver广播哦,否则仍然无效。在registerReceiver的时候注意IntentFilter的action肯定是一样的。。
另外:如果是getActivity()的情况,可以参考传送符
0 0
- Notification中PendingIntent的陷阱
- 如何设置 Notification 中PendingIntent 的 Intent
- 如何设置 Notification 中PendingIntent 的 Intent
- Notification中PendingIntent.Flag的应用
- 如何设置 Notification 中PendingIntent 的 Intent
- Android Notification中PendingIntent.Flag的应用
- 在notification中设置PendingIntent
- Notification 中PendingIntent 只打开最后一个Intent的问题
- Android 如何设置 Notification 中PendingIntent 的 Intent
- Notification PendingIntent
- Notification和PendingIntent的结合使用
- android notification pendingIntent remoteviews的基础介绍
- Android PendingIntent Notification
- Notification.Builder PendingIntent
- Notification PendingIntent NotificationManager
- 浅学Notification/PendingIntent
- PendingIntent、Notification常用方法
- Android的Notification应用详解和PendingIntent的初步剖解
- RMI远程方法调用
- 代码轻视频系列#001
- 深入理解Linux修改hostname
- Android一滴滴筆記(不間斷更新)
- UVA 129 Kypton Factor dfs构造解
- Notification中PendingIntent的陷阱
- 用java实现图片渐变叠加(3种方法)
- 校园网又抽风了,没有电影看?
- PacketFilter 包过滤类及其子类用法
- 简单区分“/”和“\”的用法
- 补血的食物有哪些?
- 成为谷歌软件工程师你需要准备什么?
- 水仙花数
- maven项目构建出现Unknown lifecycle phase "build".提示解决方法