`

PendingIntent

阅读更多
在开发SMS等应用时,有时调用相关的API会要求提供一个类型为PendingIntent的参数,那么这个PendingIntent是啥东西呢

A PendingIntent specifies an action to take in the future. It lets you pass a future
Intent to another application and allow that application to execute that Intent as
if it had the same permissions as your application, whether or not your application is still around when the Intent is eventually invoked. A PendingIntent provides a
means for applications to work, even after their process exits. It’s important to note that even after the application that created the PendingIntent has been killed, that Intent can still run.

上文来自android in action一书,总结来说就是:

1、PendingIntent可以把权限带过去,使目标应用获得当前应用的permissions
2、PendingIntent是在将来的某个时间点执行的,即使创建PendingIntent的应用在那个时候已经结束了生命周期,这个Intent依然会被执行

创建PendingIntent的代码类似于
PendingIntent.getActivity(context,requestCode,intent,flags);

context是当前的上下文;requestCode是请求代码,一般是0;intent就是将来要执行的intent;flags不知道是啥,看很多代码一般也是设置成0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics