美文网首页
PendingIntent

PendingIntent

作者: jockerMe | 来源:发表于2016-06-29 00:02 被阅读317次

    PendingIntent使用原因介绍

    用它来描述执行一个Intent和目标行为(A description of an Intent and target action to perform with is )。通过以下方法获取PendingIntent实例**```getActivity(Context, int, Intent, int),getActivities(Context, int, Intent[], int),getBroadcast(Context, int, Intent, int),getService(Context, int, Intent, int);返回的对象可以被其它应用处理,他们可以执行你在稍后时间所描述的动作。

    通过给予另一个应用一个PendingIntent,你授他权利执行你所标记的选项就好像这个应用是你的应用一样(具有相同的权限和身份)。因此你需要小心你所建立的PendingIntent,你提供的基础意图应该明确标记为你所拥有组件的组件名称,保证不会无限制的发送。

    一个PendingIntent 是一个系统描述的关联,描述用来取回的原始数据。这个以为着,即使PendingIntent的原始创建应用进程被关闭,这个PendingIntent对与接受它的其它进程仍然是可用的。如果创建应用的稍后从新收到同样的PendingIntent(same ooperation,same Intent action, data, categories, components, and same flags),他将会收到一个PendingIntent,如果它仍旧有效,他将响应相同的操作,因此可以调用cancel()删除。

    Type Constants
    int FLAG_CANCEL_CURRENT(这个标记意味着,描述PendingIntent已经存在的话,在生成一个新的PendingIntent前,当前PendingIntent应当取消)
    int FLAG_IMMUTALBE(这个标记意味着,创建的PendingIntent应该是独一无二的)
    int FLAG_NO_CREATE(这个标记意味着,如果描述PendingIntent未存在,将简单的返回一个Null,而不是创建它)
    int FLAG_ONE_SHOT(这个标记意味着,这个PendingIntent只能被使用一次)
    int FLAG_UPDATE_CURRENT(这个标记意味着,如果描述PendingIntent已经存在,将会替换以存在的PendingIntent,但是更新PendingIntent,Intent中的数据)

    公共方法

    Type Func
    void cancle()取消当前活动的PendingIntent
    int describeContents()
    bolean equals(Object otherObj)比较两个PendingIntent对象的操作者,返回Ture 代表他们来自相同的包的相同操作者
    static PendingIntent getActivities(Context context, int requestCode, Intent[] intents, int flags, Bundle options)
    static PendingIntent getActivities(Context context, int requestCode, Intent[] intents, int flags)
    static PendingIntent getActivity(Context context, int requestCode, Intent intent, int flags)
    static PendingIntent getActivity(Context context, int requestCode, Intent intent, int flags, Bundle options)生成一个PendingIntent并且打开一个新的activity,就像调用Context.startActivity(Intent)
    static PendingIntent getBroadcast(Context context, int requestCode, Intent intent, int flags) 创建一个PendingIntent并且打开一个broadcast,向调用Context.sendBroadcast()
    String getCreatorPackage()返回创建这个PendingIntent的应用的包名
    int getCreatorUid()
    UserHandle getCreatorUserHandle()
    IntentSender getIntentSender()
    static PendingIntent getService(Context context, int requestCode, Intent intent, int flags)
    int hashCode()

    相关文章

      网友评论

          本文标题:PendingIntent

          本文链接:https://www.haomeiwen.com/subject/bkwtjttx.html