PendingIntent 基本用法
来源:互联网 发布:安卓数据开关在哪 编辑:程序博客网 时间:2024/04/27 19:30
pendingIntent
字面意义:延迟的intent,等待的,未决定的Intent。主要用来在某个事件完成后执行特定的Action。pendingIntent是一种特殊的Intent。
主要的区别在于Intent的执行立刻的,而pendingIntent的执行不是立刻的。
pendingIntent执行的操作实质上是参数传进来的Intent的操作,
但是使用pendingIntent的目的在于它所包含的Intent的操作的执行是需要满足某些条件的。
二)获取的方式
要得到一个pendingIntent对象,使用方法类的静态方法:
getActivity(Context, int, Intent, int),
getBroadcast(Context, int, Intent, int),
getService(Context, int, Intent, int)分别对应着Intent的3个行为,
跳转到一个activity组件、打开一个广播组件和打开一个服务组件。
参数有4个,比较重要的事第一个和第三个,其次是第二个和第四个。
可以看到,要得到这个对象,必须传入一个Intent作为参数,
必须有context作为参数。
三)主要的用途
主要的使用的地方和例子:通知Notificatio的发送,短消息SmsManager的发送和警报器AlarmManager的执行等等。
四)Intent和PendingIntent的区别
a. Intent是立即使用的,而PendingIntent可以等到事件发生后触发,PendingIntent可以cancel
b. Intent在程序结束后即终止,而PendingIntent在程序结束后依然有效
c. PendingIntent自带Context,而Intent需要在某个Context内运行
d. Intent在原task中运行,PendingIntent在新的task中运行
五)第四个参数的值:
a)FLAG_CANCEL_CURRENT:如果构建的PendingIntent已经存在,则取消前一个,重新构建一个。
b)FLAG_NO_CREATE:如果前一个PendingIntent已经不存在了,将不再构建它。
c)FLAG_ONE_SHOT:表明这里构建的PendingIntent只能使用一次。
d)FLAG_UPDATE_CURRENT:如果构建的PendingIntent已经存在,则替换它,常用
- PendingIntent 基本用法
- Android中PendingIntent的基本用法
- PendingIntent用法
- PendingIntent用法
- PendingIntent用法
- PendingIntent 的用法
- PendingIntent 用法深入理解
- [整理]PendingIntent用法
- PendingIntent用法注意
- PendingIntent 用法深入理解
- Android:AppWidget,PendingIntent,RemoteViews用法
- Android:AppWidget,PendingIntent,RemoteViews用法
- android中pendingIntent的用法
- PendingIntent
- PendingIntent
- PendingIntent
- PendingIntent
- PendingIntent
- 【codevs 1191】数轴染色
- jvm问题排查命令
- 工作笔记——mybatis使用中SQL语句
- 赛马网基本算法之--约会问题
- 谁是最可爱的人?!——智慧城市东区一线项目员工走访纪实
- PendingIntent 基本用法
- 弱校连萌之十一大作战v10.2 G【 Road History 】
- Routing 功能概述 - 每天5分钟玩转 OpenStack(98)
- leetcode-136. Single Number 异或操作、切片
- xcode + nasm 汇编混编
- 【LeetCode】5.Longest Palindromic Substring
- yum Error: Cannot retrieve repository metadata (repomd.xml) for repository报错解决
- 最大熵模型求解:训练和学习
- 802.11n 原理解析