android PengdingIntent Extras信息

来源:互联网 发布:php点餐系统 编辑:程序博客网 时间:2024/04/29 00:55

keywords:android PengdingIntent intent Extras信息

发送通知时我们通常会在通知栏附加上一些信息,当通过通知启动某个activity时,利用这些附加信息完成某些工作,但是会遇到这类问题:在通过通知启动的activity无法获取到intent的附加信息,或者是获取的附加信息跟自己期望的不一致,不然你不间断的发通知,每个通知附加信息不一样。

n.contentIntent = PendingIntent.getActivity(getApplicationContext(), (int) info.pId, intent,PendingIntent.FLAG_UPDATE_CURRENT);
蓝色标记的切忌不能随便弄个参数糊弄。看最后解释。

之所以会犯这类错大多人估计都被PendingIntent的getActivity的requestCode这个参数的注释误导了。虽然google说它暂时没用,但是通过实践和google后,发现这个参数很有用

解释如下

Anroid reuses intents, the intent action and request code make it unique, but not the extra data. So you need to set a unique request id or use different intent actions. – Bachi Aug 15 '11 at 11:58


http://stackoverflow.com/questions/1198558/how-to-send-parameters-from-a-notification-click-to-an-activity

原创粉丝点击