`
kanwoerzi
  • 浏览: 1645415 次
文章分类
社区版块
存档分类
最新评论

PendingIntent详解

阅读更多
本文翻译整理自:<wbr style="line-height:25px"><a target="_blank" rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">http://developer.android.com/reference/android/app/PendingIntent.html</a> <div style="line-height:25px"> <div style="line-height:25px">public final class</div> <div style="line-height:25px">PendingIntent</div> <div style="line-height:25px">extends Object</div> <div style="line-height:25px">implements Parcelable</div> </div> <div style="line-height:25px"> <div style="line-height:25px"><span style="line-height:25px"><span style="font-size:16px; line-height:28px">简介</span></span></div> <div style="line-height:25px"><span style="color:#003366; line-height:25px">PendingIntent用于描述Intent及其最终的行为.</span></div> <div style="line-height:25px"> <span style="color:#003366; line-height:25px">你可以通过</span><span style=""><span style="line-height:21px; margin-right:2px"><a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context,%20int,%20android.content.Intent,%20int)" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">getActivity</a></span>(<a rel="nofollow" href="http://developer.android.com/reference/android/content/Context.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Context</a>context, int requestCode,<a rel="nofollow" href="http://developer.android.com/reference/android/content/Intent.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Intent</a>intent, int flags)</span><span style="color:#003366; line-height:25px">系列方法从系统取得一个</span><span style="color:#0000ff; line-height:25px">用于启动一个Activity的PendingIntent对象</span><span style="color:#003366; line-height:25px">,</span> </div> <div style="line-height:25px"> <span style="color:#003366; line-height:25px">可以通过</span><span style=""><span style="line-height:21px; margin-right:2px"><a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html#getService(android.content.Context,%20int,%20android.content.Intent,%20int)" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">getService</a></span>(<a rel="nofollow" href="http://developer.android.com/reference/android/content/Context.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Context</a>context, int requestCode,<a rel="nofollow" href="http://developer.android.com/reference/android/content/Intent.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Intent</a>intent, int flags)</span><span style="color:#003366; line-height:25px">方法从系统取得一个</span><span style="color:#0000ff; line-height:25px">用于启动一个Service的PendingIntent对象</span> </div> <div style="line-height:25px"> <span style="color:#003366; line-height:25px">可以通过</span><span style=""><span style="line-height:21px; margin-right:2px"><a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html#getBroadcast(android.content.Context,%20int,%20android.content.Intent,%20int)" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">getBroadcast</a></span>(<a rel="nofollow" href="http://developer.android.com/reference/android/content/Context.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Context</a>context, int requestCode,<a rel="nofollow" href="http://developer.android.com/reference/android/content/Intent.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Intent</a>intent, int flags)</span><span style="color:#003366; line-height:25px">方法从系统取</span><span style="color:#0000ff; line-height:25px">得一个用于向BroadcastReceiver的Intent广播的PendingIntent对象</span> </div> <div style="line-height:25px"><span style="color:#003366; line-height:25px">返回的PendingIntent可以递交给别的应用程序,然后继续处理。这里的话你可以稍后才处理PendingIntent中描述的Intent及其最终行为。</span></div> <div style="line-height:25px"> <span style="color:#000080; line-height:25px">当你把</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#000080; line-height:25px">递交给别的程序进行处理时,PendingIntent仍然拥有PendingIntent原程序所拥有的权限(with the same permissions and identity).</span><span style="color:#003366; line-height:25px">当你从系统取得一个PendingIntent时,一定要非常小心才行。比如,通常,如果Intent目的地是你自己的component(</span><span style="color:#0000ff; line-height:25px">Activity</span><span style="color:#003366; line-height:25px">/</span><span style="color:#0000ff; line-height:25px">Service/BroadcastReceiver</span><span style="color:#003366; line-height:25px">)的话,你最好采用在Intent中显示指定目的component名字的方式,以确保Intent最终能发到目的,否则Intent最后可能不知道发到哪里了</span><span style="color:#000080; line-height:25px">。一个</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#000080; line-height:25px">就是Android系统中的一个token(节点,这个应该是Linux或C\C++用语)的一个对象引用,它描述了一些将用于retrieve的数据(这里,这些数据描述了Intent及其最终的行为)。</span> </div> <div style="line-height:25px"> <span style="color:#000080; line-height:25px">这就意味着即使PendingIntent原进程结束了的话,</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#000080; line-height:25px">本身仍然还存在,可在其他进程(PendingIntent被递交到的其他程序)中继续使用.</span><span style="color:#003366; line-height:25px">如果我在从系统中提取一个</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#003366; line-height:25px">的,而系统中有一个和你描述的</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#003366; line-height:25px">对等的</span><span style="color:#0000ff; line-height:25px">PendingInent</span><span style="color:#003366; line-height:25px">, 那么系统会直接返回和该PendingIntent其实是同一token的</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#003366; line-height:25px">,而不是一个新的</span><span style="color:#0000ff; line-height:25px">token</span><span style="color:#003366; line-height:25px">和</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#003366; line-height:25px">。然而你在从提取</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#003366; line-height:25px">时,通过</span><span style="color:#0000ff; line-height:25px">FLAG_CANCEL_CURRENT参数</span><span style="color:#003366; line-height:25px">,让这个老</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#003366; line-height:25px">的先cancel()掉,这样得到的</span><span style="color:#0000ff; line-height:25px">pendingInten</span><span style="color:#003366; line-height:25px">和其</span><span style="color:#0000ff; line-height:25px">token</span><span style="color:#003366; line-height:25px">的就是新的了。</span> </div> <div style="line-height:25px"> <span style="color:#000080; line-height:25px">通过</span><span style="color:#0000ff; line-height:25px">FLAG_UPDATE_CURRENT参数</span><span style="color:#000080; line-height:25px">的话,可以让新的Intent会更新之前</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#000080; line-height:25px">中的Intent对象数据,例如更新Intent中的Extras</span><span style="color:#003366; line-height:25px">。另外,我们也可以在</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#003366; line-height:25px">的原进程中调用PendingIntent的cancel ()把其从系统中移除掉。</span> </div> </div> <div style="line-height:25px"><span style="color:#003366; line-height:25px"><br style="line-height:25px"></span></div> <div style="line-height:25px"> <span style="line-height:25px">注意</span>:<span style="color:#0000ff; line-height:25px">两个PendingIntent对等是指它们的operation一样, 且其它们的Intent的action, data, categories,components和flags都一样</span>。<span style="color:#ff0000; line-height:25px">但是它们的Intent的Extra可以不一样</span><span style="color:#0000ff; line-height:25px">。</span> </div> <div style="line-height:25px"><span style="line-height:25px">主要常量</span></div> <div style="line-height:25px"> <div style="line-height:25px"> <span style="color:#003366; line-height:25px">FLAG_CANCEL_CURRENT</span>:<span style="color:#000080; line-height:25px">如果当前系统中已经存在一个相同的</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#000080; line-height:25px">对象,那么就将先将已有的PendingIntent取消,然后重新生成一个</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#000080; line-height:25px">对象。</span> </div> <div style="line-height:25px"> <span style="color:#003366; line-height:25px">FLAG_NO_CREATE</span>:<span style="color:#000080; line-height:25px">如果当前系统中不存在相同的</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#000080; line-height:25px">对象,系统将不会创建该</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#000080; line-height:25px">对象而是直接返回null。</span> </div> <div style="line-height:25px"> <span style="color:#003366; line-height:25px">FLAG_ONE_SHOT<span style="line-height:25px">:</span></span><span style="color:#000080; line-height:25px">该PendingIntent只作用一次。在该</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#000080; line-height:25px">对象通过</span><span style="color:#0000ff; line-height:25px">send()</span><span style="color:#000080; line-height:25px">方法触发过后,</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#000080; line-height:25px">将自动调用</span><span style="color:#0000ff; line-height:25px">cancel()</span><span style="color:#000080; line-height:25px">进行销毁,那么如果你再调用</span><span style="color:#0000ff; line-height:25px">send()</span><span style="color:#000080; line-height:25px">方法的话,系统将会返回一个</span><span style="color:#0000ff; line-height:25px">SendIntentException</span><span style="color:#000080; line-height:25px">。</span> </div> <div style="line-height:25px"> <span style="color:#003366; line-height:25px">FLAG_UPDATE_CURRENT</span>:<span style="color:#000080; line-height:25px">如果系统中有一个和你描述的</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#000080; line-height:25px">对等的</span><span style="color:#0000ff; line-height:25px">PendingInent</span><span style="color:#000080; line-height:25px">,那么系统将使用该</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#000080; line-height:25px">对象,但是会使用新的Intent来更新之前</span><span style="color:#0000ff; line-height:25px">PendingIntent</span><span style="color:#000080; line-height:25px">中的</span><span style="color:#0000ff; line-height:25px">Intent</span><span style="color:#000080; line-height:25px">对象数据,例如更新Intent中的Extras。</span> </div> </div> <div style="line-height:25px"><span style="line-height:25px">主要成员函数</span></div> <div style="line-height:25px"><span style="line-height:25px"><span style="color:#993300; line-height:25px">getActivities系列方法</span></span></div> <div style="line-height:25px"> <span style="color:#003366; line-height:25px">该</span><span style="color:#003366; line-height:22px">系列方法将从系统取得一个</span><span style="color:#003366; line-height:22px">用于启动一个</span><span style="color:#0000ff; line-height:22px">Activity</span><span style="color:#003366; line-height:22px">的PendingIntent对象。</span> </div> <div style="line-height:25px"> <span style="line-height:25px"></span> <h4 style="line-height:normal; font-family:arial,sans-serif; margin-top:1.25em; margin-right:0px; margin-bottom:0.65em; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:1.1em; background-color:rgb(226,226,226); color:rgb(58,58,58)"> <span style="line-height:25px; font-size:0.9em">public static<a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html" style="color:rgb(0,102,153); line-height:25px; text-decoration:none">PendingIntent</a></span><span style="line-height:27px; margin-right:2px">getActivity</span><span style="line-height:25px; font-size:0.9em">(<a rel="nofollow" href="http://developer.android.com/reference/android/content/Context.html" style="color:rgb(0,102,153); line-height:25px; text-decoration:none">Context</a>context, int requestCode,<a rel="nofollow" href="http://developer.android.com/reference/android/content/Intent.html" style="color:rgb(0,102,153); line-height:25px; text-decoration:none">Intent</a>intent, int flags)</span> </h4> <div style="line-height:normal; font-family:arial,sans-serif; margin-top:-25px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:7px; padding-bottom:0px; padding-left:7px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:0.8em; color:rgb(153,153,153); float:right"> <div style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> Since:<a rel="nofollow" href="http://developer.android.com/guide/appendix/api-levels.html#level1" style="color:rgb(153,153,153); line-height:21px; text-decoration:none">API Level 1</a> </div> </div> <div style="line-height:25px; margin-top:0.5em; margin-right:0.25em; margin-bottom:0.5em; margin-left:0.25em; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <div style="line-height:25px; margin-top:0.25em; margin-right:0px; margin-bottom:0.75em; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <p style="line-height:1.3em; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px; color:rgb(51,51,51); font-family:arial,sans-serif; font-size:13px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> Retrieve a PendingIntent that will start a new activity, like calling<code style="line-height:1em; font-family:monospace; color:rgb(0,112,0)"><a rel="nofollow" href="http://developer.android.com/reference/android/content/Context.html#startActivity(android.content.Intent)" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">Context.startActivity(Intent)</a></code>. Note that the activity will be started outside of the context of an existing activity, so you must use the<code style="line-height:1em; font-family:monospace; color:rgb(0,112,0)"><a rel="nofollow" href="http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NEW_TASK" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">Intent.FLAG_ACTIVITY_NEW_TASK</a></code>launch flag in the Intent.</p> <p style="line-height:25px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> </p> <p style="line-height:25px; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <span style="font-family:arial,sans-serif; font-size:13px; color:#000080; line-height:23px">因为对于Context的startActivity方法,如果不是在其子类(Activity)中调用,那么必须对Intent加上FLAG_ACTIVITY_NEW_TASK。</span></p> </div> </div> <span style="line-height:20px; font-family:arial,sans-serif; font-size:13px"><span style="color:#000080; line-height:23px">具体可以参照<a target="_blank" rel="nofollow" href="http://developer.android.com/reference/android/content/Context.html" style="color:rgb(207,121,28); line-height:23px; text-decoration:none">Context</a>中对startActivity方法的说明或</span></span><span style="line-height:24px; font-family:Arial,Helvetica,simsun,u5b8bu4f53; white-space:nowrap">《</span><span style="line-height:24px; font-family:Arial,Helvetica,simsun,u5b8bu4f53; white-space:nowrap"><a title="阅读全文" target="_blank" href="http://hubingforever.blog.163.com/blog/static/17104057920101194575866/" style="color:rgb(207,121,28); line-height:25px; text-decoration:none; font-weight:bold">Activity和Task的基本模型</a></span><span style="line-height:24px; font-family:Arial,Helvetica,simsun,u5b8bu4f53; white-space:nowrap">》</span><span style="line-height:25px"></span> <div style="line-height:25px; margin-top:0.5em; margin-right:0.25em; margin-bottom:0.5em; margin-left:0.25em; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <div style="line-height:normal; color:rgb(51,51,51); font-family:arial,sans-serif; font-size:13px; margin-top:0.5em; margin-right:1em; margin-bottom:0.5em; margin-left:1em; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <h5 style="line-height:23px; margin-top:1em; margin-right:0px; margin-bottom:0.65em; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:1em; color:rgb(58,58,58)"> Parameters</h5> <table style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:1em; margin-left:1em; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:1em; border-collapse:collapse; empty-cells:show"><tbody style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <tr style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <th style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:2px; padding-right:10px; padding-bottom:2px; padding-left:10px; border-style:initial; border-color:initial; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; text-align:left; vertical-align:top; background-color:rgb(255,255,255); border-width:initial; border-color:initial; font-style:italic"> context</th> <td style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:2px; padding-right:10px; padding-bottom:2px; padding-left:10px; border-style:initial; border-color:initial; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; text-align:left; vertical-align:top; background-color:rgb(255,255,255); border-width:initial; border-color:initial"> The Context in which this PendingIntent should start the activity.</td> </tr> <tr style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <th style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:2px; padding-right:10px; padding-bottom:2px; padding-left:10px; border-style:initial; border-color:initial; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; text-align:left; vertical-align:top; background-color:rgb(255,255,255); border-width:initial; border-color:initial; font-style:italic"> requestCode</th> <td style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:2px; padding-right:10px; padding-bottom:2px; padding-left:10px; border-style:initial; border-color:initial; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; text-align:left; vertical-align:top; background-color:rgb(255,255,255); border-width:initial; border-color:initial"> Private request code for the sender (<span style="color:#0000ff; line-height:23px">currently not used</span>).</td> </tr> <tr style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <th style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:2px; padding-right:10px; padding-bottom:2px; padding-left:10px; border-style:initial; border-color:initial; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; text-align:left; vertical-align:top; background-color:rgb(255,255,255); border-width:initial; border-color:initial; font-style:italic"> intent</th> <td style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:2px; padding-right:10px; padding-bottom:2px; padding-left:10px; border-style:initial; border-color:initial; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; text-align:left; vertical-align:top; background-color:rgb(255,255,255); border-width:initial; border-color:initial"> Intent of the activity to be launched.</td> </tr> <tr style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <th style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:2px; padding-right:10px; padding-bottom:2px; padding-left:10px; border-style:initial; border-color:initial; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; text-align:left; vertical-align:top; background-color:rgb(255,255,255); border-width:initial; border-color:initial; font-style:italic"> flags</th> <td style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:2px; padding-right:10px; padding-bottom:2px; padding-left:10px; border-style:initial; border-color:initial; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; text-align:left; vertical-align:top; background-color:rgb(255,255,255); border-width:initial; border-color:initial"> May be<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html#FLAG_ONE_SHOT" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">FLAG_ONE_SHOT</a></code>,<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html#FLAG_NO_CREATE" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">FLAG_NO_CREATE</a></code>,<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html#FLAG_CANCEL_CURRENT" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">FLAG_CANCEL_CURRENT</a></code>,<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html#FLAG_UPDATE_CURRENT" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">FLAG_UPDATE_CURRENT</a></code>, or any of the flags as supported by<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/content/Intent.html#fillIn(android.content.Intent,%20int)" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">Intent.fillIn()</a></code>to control which unspecified parts of the intent that can be supplied when the actual send happens.<br style="line-height:23px"><span style="color:#000080; line-height:23px">当我们使用Intent.fillIn()方法时,表示其Intent的某个数据项可以被send方法的Inent参数进行覆盖重写。</span> </td> </tr> </tbody></table> </div> </div> <span style="line-height:25px"></span> <div style="line-height:25px; margin-top:0.5em; margin-right:0.25em; margin-bottom:0.5em; margin-left:0.25em; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <div style="line-height:normal; color:rgb(51,51,51); font-family:arial,sans-serif; font-size:13px; margin-top:0.5em; margin-right:1em; margin-bottom:0.5em; margin-left:1em; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <h5 style="line-height:23px; margin-top:1em; margin-right:0px; margin-bottom:0.65em; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:1em; color:rgb(58,58,58)"> Returns</h5> </div> </div> <span style="line-height:16px; color:rgb(51,51,51); font-family:arial,sans-serif; font-size:13px"> Returns an existing or new PendingIntent matching the given parameters. May return null only if<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html#FLAG_NO_CREATE" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">FLAG_NO_CREATE</a></code>has been supplied.</span> </div> <div style="line-height:25px"> <span style="line-height:normal; color:rgb(51,51,51); font-family:arial,sans-serif; font-size:13px"></span> <h4 style="line-height:25px; margin-top:1.25em; margin-right:0px; margin-bottom:0.65em; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:1.1em; background-color:rgb(226,226,226); color:rgb(58,58,58)"> <span style="line-height:23px; font-size:0.9em">public static<a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">PendingIntent</a></span><span style="line-height:25px; margin-right:2px">getActivities</span><span style="line-height:23px; font-size:0.9em">(<a rel="nofollow" href="http://developer.android.com/reference/android/content/Context.html" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">Context</a>context, int requestCode,<a rel="nofollow" href="http://developer.android.com/reference/android/content/Intent.html" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">Intent[]</a>intents, int flags)</span> </h4> <div style="line-height:21px; margin-top:-25px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:7px; padding-bottom:0px; padding-left:7px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:0.8em; color:rgb(153,153,153); float:right"> <div style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> Since:<a rel="nofollow" href="http://developer.android.com/guide/appendix/api-levels.html#level11" style="color:rgb(153,153,153); line-height:21px; text-decoration:none">API Level 11</a> </div> </div> <div style="line-height:23px; margin-top:0.5em; margin-right:0.25em; margin-bottom:0.5em; margin-left:0.25em; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <div style="line-height:1em; margin-top:0.25em; margin-right:0px; margin-bottom:0.75em; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <p style="line-height:1.3em; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> Like<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context,%20int,%20android.content.Intent,%20int)" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">getActivity(Context, int, Intent, int)</a></code>, but allows an array of Intents to be supplied. The first Intent in the array is taken as the primary key for the PendingIntent, like the single Intent given to<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context,%20int,%20android.content.Intent,%20int)" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">getActivity(Context, int, Intent, int)</a></code>. Upon sending the resulting PendingIntent, all of the Intents are started in the same way as they would be by passing them to<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/content/Context.html#startActivities(android.content.Intent%5B%5D)" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">startActivities(Intent[])</a></code>.</p> <p style="line-height:1.3em; margin-top:1em; margin-right:1em; margin-bottom:1em; margin-left:1em; padding-top:0px; padding-bottom:0px; padding-left:0.5em; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:4px; border-style:initial; border-color:initial; border-left-style:solid; border-left-color:rgb(153,170,204); border-top-color:rgb(153,170,204); border-right-color:rgb(153,170,204); border-bottom-color:rgb(153,170,204)"> The<em>first</em>intent in the array will be started outside of the context of an existing activity, so you must use the<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NEW_TASK" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">Intent.FLAG_ACTIVITY_NEW_TASK</a></code>launch flag in the Intent. (Activities after the first in the array are started in the context of the previous activity in the array, so FLAG_ACTIVITY_NEW_TASK is not needed nor desired for them.)</p> <p style="line-height:1.3em; margin-top:1em; margin-right:1em; margin-bottom:1em; margin-left:1em; padding-top:0px; padding-bottom:0px; padding-left:0.5em; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:4px; border-style:initial; border-color:initial; border-left-style:solid; border-left-color:rgb(153,170,204); border-top-color:rgb(153,170,204); border-right-color:rgb(153,170,204); border-bottom-color:rgb(153,170,204)"> The<em>last</em>intent in the array represents the key for the PendingIntent. In other words, it is the significant element for matching (as done with the single intent given to<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context,%20int,%20android.content.Intent,%20int)" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">getActivity(Context, int, Intent, int)</a></code>, its content will be the subject of replacement by<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html#send(android.content.Context,%20int,%20android.content.Intent)" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">send(Context, int, Intent)</a></code>and<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html#FLAG_UPDATE_CURRENT" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">FLAG_UPDATE_CURRENT</a></code>, etc. This is because it is the most specific of the supplied intents, and the UI the user actually sees when the intents are started.</p> <p style="line-height:1.3em; margin-top:0.5em; margin-bottom:0.5em; padding-top:0px; padding-bottom:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> </p> </div> <div style="line-height:23px; margin-top:0.5em; margin-right:1em; margin-bottom:0.5em; margin-left:1em; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <h5 style="line-height:23px; margin-top:1em; margin-right:0px; margin-bottom:0.65em; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:1em; color:rgb(58,58,58)"> Parameters</h5> <table style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:1em; margin-left:1em; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:1em; border-collapse:collapse; empty-cells:show"><tbody style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <tr style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <th style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:2px; padding-right:10px; padding-bottom:2px; padding-left:10px; border-style:initial; border-color:initial; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; text-align:left; vertical-align:top; background-color:rgb(255,255,255); border-width:initial; border-color:initial; font-style:italic"> context</th> <td style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:2px; padding-right:10px; padding-bottom:2px; padding-left:10px; border-style:initial; border-color:initial; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; text-align:left; vertical-align:top; background-color:rgb(255,255,255); border-width:initial; border-color:initial"> The Context in which this PendingIntent should start the activity.</td> </tr> <tr style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <th style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:2px; padding-right:10px; padding-bottom:2px; padding-left:10px; border-style:initial; border-color:initial; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; text-align:left; vertical-align:top; background-color:rgb(255,255,255); border-width:initial; border-color:initial; font-style:italic"> requestCode</th> <td style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:2px; padding-right:10px; padding-bottom:2px; padding-left:10px; border-style:initial; border-color:initial; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; text-align:left; vertical-align:top; background-color:rgb(255,255,255); border-width:initial; border-color:initial"> Private request code for the sender (currently not used).</td> </tr> <tr style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <th style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:2px; padding-right:10px; padding-bottom:2px; padding-left:10px; border-style:initial; border-color:initial; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; text-align:left; vertical-align:top; background-color:rgb(255,255,255); border-width:initial; border-color:initial; font-style:italic"> intents</th> <td style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:2px; padding-right:10px; padding-bottom:2px; padding-left:10px; border-style:initial; border-color:initial; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; text-align:left; vertical-align:top; background-color:rgb(255,255,255); border-width:initial; border-color:initial"> Array of Intents of the activities to be launched.</td> </tr> <tr style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <th style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:2px; padding-right:10px; padding-bottom:2px; padding-left:10px; border-style:initial; border-color:initial; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; text-align:left; vertical-align:top; background-color:rgb(255,255,255); border-width:initial; border-color:initial; font-style:italic"> flags</th> <td style="line-height:23px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:2px; padding-right:10px; padding-bottom:2px; padding-left:10px; border-style:initial; border-color:initial; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none; text-align:left; vertical-align:top; background-color:rgb(255,255,255); border-width:initial; border-color:initial"> May be<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html#FLAG_ONE_SHOT" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">FLAG_ONE_SHOT</a></code>,<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html#FLAG_NO_CREATE" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">FLAG_NO_CREATE</a></code>,<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html#FLAG_CANCEL_CURRENT" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">FLAG_CANCEL_CURRENT</a></code>,<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html#FLAG_UPDATE_CURRENT" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">FLAG_UPDATE_CURRENT</a></code>, or any of the flags as supported by<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/content/Intent.html#fillIn(android.content.Intent,%20int)" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">Intent.fillIn()</a></code>to control which unspecified parts of the intent that can be supplied when the actual send happens.<br style="line-height:23px"><span style="color:#000080; line-height:23px">当我们使用Inent.fillIn()所支持的flags时,表示其Intent的数据项可以被send方法的Intent参数覆盖重写。</span> </td> </tr> </tbody></table> </div> <div style="line-height:23px; margin-top:0.5em; margin-right:1em; margin-bottom:0.5em; margin-left:1em; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <h5 style="line-height:23px; margin-top:1em; margin-right:0px; margin-bottom:0.65em; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:1em; color:rgb(58,58,58)"> Returns</h5> <ul style="line-height:1.3em; margin-top:0px; margin-right:0px; margin-bottom:1em; margin-left:1em; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; list-style-type:none; list-style-position:initial"><li style="line-height:1.3em; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:2px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> Returns an existing or new PendingIntent matching the given parameters. May return null only if<code style="line-height:1em; color:rgb(0,112,0); font-family:monospace"><a rel="nofollow" href="http://developer.android.com/reference/android/app/PendingIntent.html#FLAG_NO_CREATE" style="color:rgb(0,102,153); line-height:23px; text-decoration:none">FLAG_NO_CREATE</a></code>has been supplied.</li></ul> </div> </div> </div> </wbr>
getService方法
该方法将系统取得一个用于启动一个Service的PendingIntent对象.

public staticPendingIntentgetService(Contextcontext, int requestCode,Intentintent, int flags)

Since:API Level 1

Retrieve a PendingIntent that will start a service, like callingContext.startService(). The start arguments given to the service will come from the extras of the Intent.

Parameters
context requestCode intent flags
The Context in which this PendingIntent should start the service.
Private request code for the sender (currently not used).
An Intent describing the service to be started.
May beFLAG_ONE_SHOT,FLAG_NO_CREATE,FLAG_CANCEL_CURRENT,FLAG_UPDATE_CURRENT, or any of the flags as supported byIntent.fillIn()to control which unspecified parts of the intent that can be supplied when the actual send happens.
当我们使用Intent.fillIn()方法的flags时,它表示其Intent的数据项可以被send方法的Intent参数覆盖重写。
Returns
  • Returns an existing or new PendingIntent matching the given parameters. May return null only ifFLAG_NO_CREATEhas been supplied.
getBroadcast方法
该方法将从系统取得一个用于向BroadcastReceiver的Intent广播的PendingIntent对象

public staticPendingIntentgetBroadcast(Contextcontext, int requestCode,Intentintent, int flags)

Since:API Level 1

Retrieve a PendingIntent that will perform a broadcast, like callingContext.sendBroadcast().

Parameters
context requestCode intent flags
The Context in which this PendingIntent should perform the broadcast.
Private request code for the sender (currently not used).
The Intent to be broadcast.
May beFLAG_ONE_SHOT,FLAG_NO_CREATE,FLAG_CANCEL_CURRENT,FLAG_UPDATE_CURRENT, or any of the flags as supported byIntent.fillIn()to control which unspecified parts of the intent that can be supplied when the actual send happens.
当我们使用Intent.fillIn()方法的flags时,它表示其Intent的数据项可以被send方法的Intent参数覆盖重写。
Returns
  • Returns an existing or new PendingIntent matching the given parameters. May return null only ifFLAG_NO_CREATEhas been supplied.
send系列方
该系列主要用于触发PendingIntent的Intent行为。用其Intent或启动一个Activity,或启动一个Service,或向BroadcastReceiver发送Intent广播。

public voidsend()

Since:API Level 1

Perform the operation associated with this PendingIntent.

Throws
PendingIntent.CanceledException
Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.

public voidsend(Contextcontext, int code,Intentintent)

Since:API Level 1

Perform the operation associated with this PendingIntent, allowing the caller to specify information about the Intent to use.

Parameters
context code intent
The Context of the caller.
该参数是因为intent参数才需要提供的,所用如果你的intent参数不为null的话,该参数也不能为null.
Result code to supply back to the PendingIntent's target.
Additional Intent data. SeeIntent.fillIn()for information on how this is applied to the original Intent.
Throws
PendingIntent.CanceledException
Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.

public voidsend(int code,PendingIntent.OnFinishedonFinished,Handlerhandler)

Since:API Level 1

Perform the operation associated with this PendingIntent, allowing the caller to be notified when the send has completed.

Parameters
code onFinished handler
Result code to supply back to the PendingIntent's target.
The object to call back on when the send has completed, or null for no callback.
通过该参数,我们可以设置在Intent发送成功后的回调函数。
Handler identifying the thread on which the callback should happen. If null, the callback will happen from the thread pool of the process.
用于说明onFinished参数指定的回调函数,最终在哪个Handler中进行调用。
Throws
PendingIntent.CanceledException
Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.

public voidsend(Contextcontext, int code,Intentintent,PendingIntent.OnFinishedonFinished,Handlerhandler)

Since:API Level 1

Perform the operation associated with this PendingIntent, allowing the caller to specify information about the Intent to use and be notified when the send has completed.

For the intent parameter, a PendingIntent often has restrictions on which fields can be supplied here, based on how the PendingIntent was retrieved ingetActivity(Context, int, Intent, int),getBroadcast(Context, int, Intent, int), orgetService(Context, int, Intent, int).

Parameters
context code intent onFinished handler
The Context of the caller. This may be null ifintentis also null.
该参数是因为intent参数才需要提供的,一般是当前的context,如果你的intent参数不为null话,该函数也不能为null.
Result code to supply back to the PendingIntent's target.
Additional Intent data. SeeIntent.fillIn()for information on how this is applied to the original Intent. Use null to not modify the original Intent.
The object to call back on when the send has completed, or null for no callback.
通过该参数,我们可以指定Intent发送成功后的回调函数。
Handler identifying the thread on which the callback should happen. If null, the callback will happen from the thread pool of the process.
该参数说明onFinished参数指定的回调函数将在哪个Handler中进行调用。
Throws
PendingIntent.CanceledException
Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.
cancel()函数

public voidcancel()

Since:API Level 1

Cancel a currently active PendingIntent. Only the original application owning an PendingIntent can cancel it.

只有PengdingIntent的原应用程序才能调用cancel()来把它从系统中移除掉。

getTargetPackage()函数

publicStringgetTargetPackage()

Since:API Level 1

Return the package name of the application that created this PendingIntent, that is the identity under which you will actually be sending the Intent. The returned string is supplied by the system, so that an application can not spoof its package.

Returns
  • The package name of the PendingIntent, or null if there is none associated with it.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics