开发手记--Notification跳转传值问题

来源:互联网 发布:网络大电影拍摄时间 编辑:程序博客网 时间:2024/06/10 20:17

 在创建Notification通知时,点击通知时跳转activity传值,发现每次传入的值都一样,都是第一次传入的值,没有更新数据,后来发现是在

 .setContentIntent(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
flag传入PendingIntent.FLAG_UPDATE_CURRENT

以下是创建通知及传值代码,isp是传入的一个对象。

Intent intent=new Intent(this, ProviderEvalDetailActivity.class);        intent.putExtra("rating", (Serializable) isp);        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);        NotificationCompat.Builder build = new NotificationCompat.Builder(this)                //设置小图标                .setSmallIcon(R.mipmap.ic_launcher)                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))                //设置通知标题                .setContentTitle("内部应用")                //设置通知内容                .setContentText("您收到一条新消息")                .setDefaults(Notification.DEFAULT_ALL)                //设置通知时间,默认为系统发出通知的时间,通常不用设置//                .setWhen(System.currentTimeMillis())                .setTicker("测试通知来啦")                //通过builder.build()方法生成Notification对象,并发送通知                .setContentIntent(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));        Notification notification=build.build();        notification.flags=Notification.FLAG_AUTO_CANCEL;        manager.notify(1, notification);

原创粉丝点击