Android · PendingIntent学习
2024-10-20 11:39:40
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);
}
最新文章
- IOS学习之初识KVO
- javascript运算符语法概述
- [MVC_Json序列化]MVC之Json序列化循环引用
- JAVA NIO是什么(zz)
- eclipse折叠快捷键
- poj 1459 Power Network
- C51关键字
- [HDOJ4635]Strongly connected(强连通分量,缩点)
- [转]亿级Web系统搭建:单机到分布式集群
- 【ASP.NET Core】解决“The required antiforgery cookie ";xxx"; is not present”的错误
- 团队作业7——第二次项目冲刺(Beta版本12.10)
- [ZJOI2008]生日聚会
- 5、使用Libgdx设计一个简单的游戏------雨滴
- 「ZJOI Day2」游记
- python AES加密 ECB PKCS5
- 【分布式缓存系列】集群环境下Redis分布式锁的正确姿势
- zabbix监控自动发现监控tomcat(V1)
- ubuntu16.04+caffe+python接口配置
- c++对象工厂
- Mysql中select的正确姿势
热门文章
- T-SQL百万记录中分组取最大值方法ROW_NUMBER() OVER()
- 【CF1015D】Walking Between Houses(构造,贪心)
- 33个好用的图片轮显 jquery图片轮显
- k-mean聚类学习笔记
- kafka术语
- class.getDeclaredFields()与class.getFields()
- c#随机生成汉字、字母、数字
- hihoCoder #1586 : Minimum-结构体版线段树(单点更新+区间最值求区间两数最小乘积) (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
- Codeforces 707C. Pythagorean Triples-推公式的数学题
- spring 基础