PendingIntent 传值 需注意,以及其四个flag常量

来源:互联网 发布:大数据时代 pdf 编辑:程序博客网 时间:2024/05/01 08:18

常用通知类型的消息

 long time=SystemClock.elapsedRealtime(); MyLog.e("RingingActivity ",String.format(Locale.getDefault(), "onclick time = %s;", time)); Intent i=new Intent(this,RingingActivity.class);  Bundle b=new Bundle();  b.putLong("t", time); i.putExtra("t", time); i.putExtra("b", b); Notification n=new Notification(R.drawable.ic_launcher, "看看notification里面的时间是否变化了", System.currentTimeMillis()); PendingIntent pi=PendingIntent.getActivity(this, 0, i,PendingIntent.FLAG_UPDATE_CURRENT);// FLAG_UPDATE_CURRENT更新Intent;// FLAG_CANCEL_CURRENT;bu更新Pending;// FLAG_ONE_SHOT获取的PendingIntent只能使用一次,再使用PendingIntent也将失败// FLAG_NO_CREAT获取的PendingIntent若描述的Intent不存在则返回NULL值. n.setLatestEventInfo(this, "消息标题", "消息内容", pi); NotificationManager nm=(NotificationManager) getSystemService(NOTIFICATION_SERVICE); nm.notify(88, n);

 

当intent 传值出现问题和还有一种情况:就是单例的Activity:OnNewIntent 不走OnCreate 这个方法


===================================================扩展,灵活的Notification创建============================================

后续添加,今天心情不好









0 0
原创粉丝点击