Intent 是及时启动,intent 随所在的activity 消失而消失

PendingIntent用于处理即将发生的事情。比如在通知Notification中用于跳转页面,但不是马上跳转。

 

PendingIntent 可以看作是对intent的包装,pendingintent中保存有当前App的Context,使它赋予外部App一种能力,使得外部App可以如同当前App一样的执行pendingintent里的 Intent, 就算在执行时当前App已经不存在了,也能通过存在pendingintent里的Context照样执行Intent。

	private void showNotify(){
Intent notificationIntent = new Intent(this,MainActivity.class); //点击该通知后要跳转的Activity
PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,0);
Notification notice = new Notification.Builder(this)
.setContentTitle("New mail from Man_hua")
.setContentText("this is a test")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(contentIntent)
.setAutoCancel(true)
.setVibrate(new long[] { 100, 250, 100, 500 })
.build(); NotificationManager manager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0,notice);
}

最新文章

  1. IOS学习之初识KVO
  2. javascript运算符语法概述
  3. [MVC_Json序列化]MVC之Json序列化循环引用
  4. JAVA NIO是什么(zz)
  5. eclipse折叠快捷键
  6. poj 1459 Power Network
  7. C51关键字
  8. [HDOJ4635]Strongly connected(强连通分量,缩点)
  9. [转]亿级Web系统搭建:单机到分布式集群
  10. 【ASP.NET Core】解决“The required antiforgery cookie "xxx" is not present”的错误
  11. 团队作业7——第二次项目冲刺(Beta版本12.10)
  12. [ZJOI2008]生日聚会
  13. 5、使用Libgdx设计一个简单的游戏------雨滴
  14. 「ZJOI Day2」游记
  15. python AES加密 ECB PKCS5
  16. 【分布式缓存系列】集群环境下Redis分布式锁的正确姿势
  17. zabbix监控自动发现监控tomcat(V1)
  18. ubuntu16.04+caffe+python接口配置
  19. c++对象工厂
  20. Mysql中select的正确姿势

热门文章

  1. T-SQL百万记录中分组取最大值方法ROW_NUMBER() OVER()
  2. 【CF1015D】Walking Between Houses(构造,贪心)
  3. 33个好用的图片轮显 jquery图片轮显
  4. k-mean聚类学习笔记
  5. kafka术语
  6. class.getDeclaredFields()与class.getFields()
  7. c#随机生成汉字、字母、数字
  8. hihoCoder #1586 : Minimum-结构体版线段树(单点更新+区间最值求区间两数最小乘积) (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
  9. Codeforces 707C. Pythagorean Triples-推公式的数学题
  10. spring 基础