PendingIntent 概述

  PendingIntent 是某个不确定的时刻发生的意图, 而Intent 是立刻发生。PendingIntent  典型的应用场景是给 RemoteViews 添加单击事件, 因为RemoteViews 运行在远程进程中, 因此 RemoteViews 不同于普通的View, 所以无法直接通过 setOnClickListener 方法来设置单击事件。 PendingIntent 通过send 和 cancel 方法来发生和取消待定的 Intent.

  PendingIntent 支持三种待定意图: 启动Activity、 Service、 和发送广播, 对应有3个接口方法。

                                     PendingIntent 的主要方法

static PendingIntent

getActivity(Context context, int requestCode, Intent intent, int flags)

 获得一个PendingIntent, 该待定意图发生时, 效果相当于Context.startActivity(Intent)

static PendingIntent

getService(Context context, int requestCode, Intent intent, int flags)

 获得一个PendingIntent, 该待定意图发生时, 效果相当于Context.startService(Intent)

static PendingIntent

getBroadcast(Context context, int requestCode, Intent intent, int flags)

 获得一个PendingIntent, 该待定意图发生时, 效果相当于Context.sendBroadcast(Intent)

 

  PendingIntent 的匹配规则为: 当他们的内部Intent 和 RequestCode 都相同, 则两个PendingIntent 相同。 requestCode 会影响到flags 的效果。 常见的有四种flags。

 


        

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值