android 使用Notification弹多个通知时,点击跳转intent取值时总是最后一个
2016-04-21 11:42
696 查看
最近开发中模块功能,使用NotificationManager触发多个Notification:
最后修改为:
private void showIMNotification(Context context, String ticker, Bitmap defaultBitmap, UnreadEntity unreadEntity, int notificationId) { Intent intent = new Intent(CHATATION_FLAG); intent.putExtra("chat_session_key", unreadEntity.getSessionKey()); NotificationManager manager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Notification notify1 = new Notification(); notify1.icon = R.drawable.logo; notify1.when = System.currentTimeMillis(); String appName = ""; try { ApplicationInfo appInfo = context.getPackageManager() .getApplicationInfo( PhoneTools.getPackageInfo(context).packageName, PackageManager.GET_META_DATA); appName = appInfo.metaData.getString("MY_APP_LABEL"); } catch (NameNotFoundException e) { e.printStackTrace(); appName = context.getString(R.string.app_name); } notify1.tickerText = ticker; notify1.setLatestEventInfo(context, appName, ticker, pendingIntent); notify1.number = 1; notify1.flags |= Notification.FLAG_AUTO_CANCEL; manager.notify(notificationId, notify1); }每次调用都是新的intent,但是跳转到对应的activity取值时,发现每次都是取最后一个notification intent里的值,然后网上查资料以后发现:问题主要出在PendingIntent.getActivity()的第二个参数,平常demo直接写0的,应用场景不同所以没出问题,实际上是通过该参数来区别不同的intent的,如果id相同,就会覆盖掉之前的intent了。所以总是获取到最后一个intent。
最后修改为:
PendingIntent pendingIntent = PendingIntent.getActivity(context, StringUtil.getIntUUID(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
相关文章推荐
- android progressBar 自定义 进度颜色
- 我的Android进阶之旅------>解决AES加密报错:java.security.InvalidKeyException: Unsupported key size: 18 bytes
- Android 使用Drawable实现圆角与圆形图案
- android studio批量打包执行
- Android wear开发真机调试报: Android error: Failed to install *.apk on device *: timeout
- android 自学日记(四) ---ActionBar
- Android RecyclerView初探
- Android Fragment嵌套使用存在的一些BUG以及解决方法
- android studio中批量混淆打包
- [置顶] java生成四位随机数,包含数字和字母 区分大小写,特别适合做验证码,android开发
- Android Fragment中onActivityResult()方法获取不到返回数据或者无响应的解决办法
- android上拉刷新下拉加载
- Android和H5的交互问题
- Android应用Design Support Library 使用研究
- android源码/内核下载
- 在Android 5.0中使用JobScheduler
- Android Animations动画使用详解
- android loader用法
- 添加Android系统设置项
- Android加载图片导致内存溢出(Out of Memory异常)