Notification内的Intent Extra数据不能更新的问题
2011-11-18 19:56
411 查看
最近小弟在编写一个关于后台数据处理的服务时发现在NotificationManager发送的Notification的PendingIntent内的Intent的Extra数据无法更新,甚至无法获得,测试后发现,相同ID的Notification只能存储第一个Intent的数据,即使使用NotificationManager.cancel也无济于事。
在仔细查看了相关API后发现,使用PendingIntent.getActivity(mContext, 0,mActivity, 0);函数时,将flag置为了0,这时的PendingIntent无法更新,所以发出的Notification打开后,目标Activity无法从getIntent()获取额外的数据,根据API,将getActivity函数的flag值置为PendingIntent.FLAG_UPDATE_CURRENT或者PendingIntent.FLAG_CANCEL_CURRENT即可。
另外放上PendingIntent.getActivity函数可以用到的几个flag值含义:
0:
Default value, if the described PendingIntent already exists, then keep it without change.
Flag for use with
creating it.
Constant Value: 536870912 (0x20000000)
Flag for use with
called on it, it will be automatically canceled for you and any future attempt to send through it will fail.
Constant Value: 1073741824 (0x40000000)
Flag for use with
with what is in this new Intent. This can be used if you are creating intents where only the extras change, and don't care that any entities that received your previous PendingIntent will be able to launch it with your new extras even if they are not explicitly
given to it.
Constant Value: 134217728 (0x08000000)
在仔细查看了相关API后发现,使用PendingIntent.getActivity(mContext, 0,mActivity, 0);函数时,将flag置为了0,这时的PendingIntent无法更新,所以发出的Notification打开后,目标Activity无法从getIntent()获取额外的数据,根据API,将getActivity函数的flag值置为PendingIntent.FLAG_UPDATE_CURRENT或者PendingIntent.FLAG_CANCEL_CURRENT即可。
另外放上PendingIntent.getActivity函数可以用到的几个flag值含义:
0:
Default value, if the described PendingIntent already exists, then keep it without change.
FLAG_CANCEL_CURRENT:
Flag for use with getActivity(Context, int, Intent, int)
, getBroadcast(Context,
int, Intent, int)
, and getService(Context, int, Intent, int)
: if the described PendingIntent already exists, the current one is canceled before generating
a new one. You can use this to retrieve a new PendingIntent when you are only changing the extra data in the Intent; by canceling the previous pending intent, this ensures that only entities given the new data will be able to launch it. If this assurance is
not an issue, consider FLAG_UPDATE_CURRENT
.
Constant Value: 268435456 (0x10000000)
FLAG_NO_CREATE:
Flag for use with getActivity(Context, int, Intent, int),
getBroadcast(Context, int, Intent, int), and
getService(Context, int, Intent, int): if the described PendingIntent does not already exist, then simply return null instead of
creating it.
Constant Value: 536870912 (0x20000000)
FLAG_ONE_SHOT:
Flag for use with getActivity(Context, int, Intent, int),
getBroadcast(Context, int, Intent, int), and
getService(Context, int, Intent, int): this PendingIntent can only be used once. If set, after
send()is
called on it, it will be automatically canceled for you and any future attempt to send through it will fail.
Constant Value: 1073741824 (0x40000000)
FLAG_UPDATE_CURRENT:
Flag for use with getActivity(Context, int, Intent, int),
getBroadcast(Context, int, Intent, int), and
getService(Context, int, Intent, int): if the described PendingIntent already exists, then keep it but its replace its extra data
with what is in this new Intent. This can be used if you are creating intents where only the extras change, and don't care that any entities that received your previous PendingIntent will be able to launch it with your new extras even if they are not explicitly
given to it.
Constant Value: 134217728 (0x08000000)
相关文章推荐
- Notification内的Intent Extra数据不能更新的问题
- Notification内的Intent Extra数据不能更新的问题
- notification PendingIntent跳转数据不更新问题
- angular2回调函数与数据绑定不能实时更新的问题
- Notification(二)——PendingIntent的flag导致数据相同的问题
- 关于Intent传递数据的问题(持续更新)
- SQL 已更新或删除的行值要么不能使该行成为唯一行(sqlserver中有多行所有的列重复的数据,无法更新或删除问题)
- Notification(二)——PendingIntent的flag导致数据同样的问题
- SharedPreferences 数据不能更新的问题
- 问题:Hibernate中数据始终不能更新? 这个问题整死我了!
- WPF线程中被修改后DataGrid数据不能及时更新的问题
- arcims不能刷新更新数据问题
- Notification中Intent携带数据重复问题
- 解决TextView数据不能更新的问题以及Android Button事件响应函数的两种方法
- android中多次调用PendingIntent.getBroadcast(),intent数据不更新问题
- android 多次调用PendingIntent.getBroadcast intent数据不更新问题
- 解决Notification PendingIntent意图打开Activity数据没有更新的问题
- SQL 已更新或删除的行值要么不能使该行成为唯一行(sqlserver中有多行所有的列重复的数据,无法更新或删除问题)
- android 多次调用PendingIntent.getBroadcast intent数据不更新问题
- SQL 已更新或删除的行值要么不能使该行成为唯一行(sqlserver中有多行所有的列重复的数据,无法更新或删除问题)