android 使用Notification弹多个通知时,点击跳转intent取值时总是最后一个
来源:互联网 发布:linux执行文件命令 编辑:程序博客网 时间:2024/06/03 16:55
最近开发中模块功能,使用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);
0 0
- android 使用Notification弹多个通知时,点击跳转intent取值时总是最后一个
- Android 通知栏Notification点击跳转无效
- Android Notification多个通知跳转Activity总会被最后一个替换的问题
- Notification通知,点击通知后跳转
- Notification通知点击无效,无法跳转问题
- 通知的点击跳转(Notification)
- Android 使用Notification(通知)
- android Notification通知使用
- android-Notification点击跳转Activity
- Android Notification的基本使用和点击跳转中的注意事项
- Android 点击通知栏 跳转
- android通知(Notification)的使用
- android Notification(通知) 的使用
- Android 通知 Notification 使用详情
- Android通知Notification的使用
- android 使用通知(Notification)
- Android Notification(一)使用通知
- Android中使用通知Notification
- java写单例模式
- 在Android 5.0中使用JobScheduler
- MySQL 数据库操作
- php设计模式 工厂模式
- c++作业4
- android 使用Notification弹多个通知时,点击跳转intent取值时总是最后一个
- PHP如何定义表关联 hasOne 与 belongsTo
- Windows Server 2008r2配置主DNS域名服务器
- Nginx+Tomcat负载均衡
- Hibernate初识
- CUDA中一些error的解决方法
- html字体大小em
- JavaScript Date对象
- RDD原理与详解