青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

life02

  C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
  197 隨筆 :: 3 文章 :: 37 評論 :: 0 Trackbacks

PendingIntent詳解 

http://hubingforever.blog.163.com/blog/static/17104057920117275222472/

2011-08-05 10:13:04|  分類: Android基礎(chǔ) |  標簽:pendingintent   |字號 訂閱

本文翻譯整理自:http://developer.android.com/reference/android/app/PendingIntent.html
public final class
PendingIntent
extends Object
implements Parcelable
簡介
PendingIntent用于描述Intent及其最終的行為. 
你可以通過getActivity(Context context, int requestCode, Intent intent, int flags)系列方法從系統(tǒng)取得一個用于啟動一個Activity的PendingIntent對象,
可以通過getService(Context context, int requestCode, Intent intent, int flags)方法從系統(tǒng)取得一個用于啟動一個Service的PendingIntent對象
可以通過getBroadcast(Context context, int requestCode, Intent intent, int flags)方法從系統(tǒng)取得一個用于向BroadcastReceiver的Intent廣播的PendingIntent對象
返回的PendingIntent可以遞交給別的應(yīng)用程序,然后繼續(xù)處理。這里的話你可以稍后才處理PendingIntent中描述的Intent及其最終行為。
當你把PendingIntent遞交給別的程序進行處理時,PendingIntent仍然擁有PendingIntent原程序所擁有的權(quán)限(with the same permissions and identity).當你從系統(tǒng)取得一個PendingIntent時,一定要非常小心才行。比如,通常,如果Intent目的地是你自己的component(Activity/Service/BroadcastReceiver)的話,你最好采用在Intent中顯示指定目的component名字的方式,以確保Intent最終能發(fā)到目的,否則Intent最后可能不知道發(fā)到哪里了。一個PendingIntent就是Android系統(tǒng)中的一個token(節(jié)點,這個應(yīng)該是Linux或C\C++用語)的一個對象引用,它描述了一些將用于retrieve的數(shù)據(jù)(這里,這些數(shù)據(jù)描述了Intent及其最終的行為)。
這就意味著即使PendingIntent原進程結(jié)束了的話, PendingIntent本身仍然還存在,可在其他進程(PendingIntent被遞交到的其他程序)中繼續(xù)使用.如果我在從系統(tǒng)中提取一個PendingIntent的,而系統(tǒng)中有一個和你描述的PendingIntent對等的PendingInent, 那么系統(tǒng)會直接返回和該PendingIntent其實是同一token的PendingIntent,而不是一個新的token和PendingIntent。然而你在從提取PendingIntent時,通過FLAG_CANCEL_CURRENT參數(shù),讓這個老PendingIntent的先cancel()掉,這樣得到的pendingInten和其token的就是新的了。
通過FLAG_UPDATE_CURRENT參數(shù)的話,可以讓新的Intent會更新之前PendingIntent中的Intent對象數(shù)據(jù),例如更新Intent中的Extras。另外,我們也可以在PendingIntent的原進程中調(diào)用PendingIntent的cancel ()把其從系統(tǒng)中移除掉。
注意:兩個PendingIntent對等是指它們的operation一樣, 且其它們的Intent的action, data, categories, components和flags都一樣。但是它們的Intent的Extra可以不一樣。
主要常量
FLAG_CANCEL_CURRENT:如果當前系統(tǒng)中已經(jīng)存在一個相同的PendingIntent對象,那么就將先將已有的PendingIntent取消,然后重新生成一個PendingIntent對象。
FLAG_NO_CREATE:如果當前系統(tǒng)中不存在相同的PendingIntent對象,系統(tǒng)將不會創(chuàng)建該PendingIntent對象而是直接返回null。
FLAG_ONE_SHOT:該PendingIntent只作用一次。在該PendingIntent對象通過send()方法觸發(fā)過后,PendingIntent將自動調(diào)用cancel()進行銷毀,那么如果你再調(diào)用send()方法的話,系統(tǒng)將會返回一個SendIntentException。
FLAG_UPDATE_CURRENT:如果系統(tǒng)中有一個和你描述的PendingIntent對等的PendingInent,那么系統(tǒng)將使用該PendingIntent對象,但是會使用新的Intent來更新之前PendingIntent中的Intent對象數(shù)據(jù),例如更新Intent中的Extras。
主要成員函數(shù)
getActivities系列方法
該系列方法將從系統(tǒng)取得一個用于啟動一個Activity的PendingIntent對象。

public static PendingIntent getActivity (Context context, int requestCode, Intent intent, int flags)

Since: API Level 1

Retrieve a PendingIntent that will start a new activity, like calling Context.startActivity(Intent). Note that the activity will be started outside of the context of an existing activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK launch flag in the Intent.

因為對于Context的startActivity方法,如果不是在其子類(Activity)中調(diào)用,那么必須對Intent加上FLAG_ACTIVITY_NEW_TASK。

具體可以參照Context中對startActivity方法的說明或Activity和Task的基本模型
Parameters
contextThe Context in which this PendingIntent should start the activity.
requestCodePrivate request code for the sender (currently not used).
intentIntent of the activity to be launched.
flagsMay be FLAG_ONE_SHOTFLAG_NO_CREATEFLAG_CANCEL_CURRENTFLAG_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()方法時,表示其Intent的某個數(shù)據(jù)項可以被send方法的Inent參數(shù)進行覆蓋重寫。
Returns
  Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.

public static PendingIntent getActivities (Context context, int requestCode, Intent[] intents, int flags)

Since: API Level 11

Like getActivity(Context, int, Intent, int), 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 getActivity(Context, int, Intent, int). Upon sending the resulting PendingIntent, all of the Intents are started in the same way as they would be by passing them to startActivities(Intent[]).

The first intent in the array will be started outside of the context of an existing activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK 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.)

The last 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 togetActivity(Context, int, Intent, int), its content will be the subject of replacement by send(Context, int, Intent) andFLAG_UPDATE_CURRENT, 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.

Parameters
contextThe Context in which this PendingIntent should start the activity.
requestCodePrivate request code for the sender (currently not used).
intentsArray of Intents of the activities to be launched.
flagsMay be FLAG_ONE_SHOTFLAG_NO_CREATEFLAG_CANCEL_CURRENTFLAG_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.
當我們使用Inent.fillIn()所支持的flags時,表示其Intent的數(shù)據(jù)項可以被send方法的Intent參數(shù)覆蓋重寫。
Returns
  • Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.
getService方法
該方法將系統(tǒng)取得一個用于啟動一個Service的PendingIntent對象.

public static PendingIntent getService (Context context, int requestCode, Intent intent, int flags)

Since: API Level 1

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

Parameters
contextThe Context in which this PendingIntent should start the service.
requestCodePrivate request code for the sender (currently not used).
intentAn Intent describing the service to be started.
flagsMay be FLAG_ONE_SHOTFLAG_NO_CREATEFLAG_CANCEL_CURRENTFLAG_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的數(shù)據(jù)項可以被send方法的Intent參數(shù)覆蓋重寫。
Returns
  • Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.
getBroadcast方法
該方法將從系統(tǒng)取得一個用于向BroadcastReceiver的Intent廣播的PendingIntent對象

public static PendingIntent getBroadcast (Context context, int requestCode, Intent intent, int flags)

Since: API Level 1

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

Parameters
contextThe Context in which this PendingIntent should perform the broadcast.
requestCodePrivate request code for the sender (currently not used).
intentThe Intent to be broadcast.
flagsMay be FLAG_ONE_SHOTFLAG_NO_CREATEFLAG_CANCEL_CURRENTFLAG_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的數(shù)據(jù)項可以被send方法的Intent參數(shù)覆蓋重寫。
Returns
  • Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.
send系列方
該系列主要用于觸發(fā)PendingIntent的Intent行為。用其Intent或啟動一個Activity,或啟動一個Service,或向BroadcastReceiver發(fā)送Intent廣播。

public void send ()

Since: API Level 1

Perform the operation associated with this PendingIntent.

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

public void send (Context context, int code, Intent intent)

Since: API Level 1

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

Parameters
contextThe Context of the caller.
該參數(shù)是因為intent參數(shù)才需要提供的,所用如果你的intent參數(shù)不為null的話,該參數(shù)也不能為null.
codeResult code to supply back to the PendingIntent's target.
intentAdditional Intent data. See Intent.fillIn() for information on how this is applied to the original Intent.
Throws
PendingIntent.CanceledExceptionThrows CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.

public void send (int code, PendingIntent.OnFinished onFinished, Handler handler)

Since: API Level 1

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

Parameters
codeResult code to supply back to the PendingIntent's target.
onFinishedThe object to call back on when the send has completed, or null for no callback.
通過該參數(shù),我們可以設(shè)置在Intent發(fā)送成功后的回調(diào)函數(shù)。
handlerHandler identifying the thread on which the callback should happen. If null, the callback will happen from the thread pool of the process.
用于說明onFinished參數(shù)指定的回調(diào)函數(shù),最終在哪個Handler中進行調(diào)用。
Throws
PendingIntent.CanceledExceptionThrows CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.

public void send (Context context, int code, Intent intent, PendingIntent.OnFinished onFinished, Handler handler)

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), or getService(Context, int, Intent, int).

Parameters
contextThe Context of the caller. This may be null if intent is also null.
該參數(shù)是因為intent參數(shù)才需要提供的,一般是當前的context,如果你的intent參數(shù)不為null的話,該函數(shù)也不能為null.
codeResult code to supply back to the PendingIntent's target.
intentAdditional Intent data. See Intent.fillIn() for information on how this is applied to the original Intent. Use null to not modify the original Intent.
onFinishedThe object to call back on when the send has completed, or null for no callback.
通過該參數(shù),我們可以指定Intent發(fā)送成功后的回調(diào)函數(shù)。
handlerHandler identifying the thread on which the callback should happen. If null, the callback will happen from the thread pool of the process.
該參數(shù)說明onFinished參數(shù)指定的回調(diào)函數(shù)將在哪個Handler中進行調(diào)用。
Throws
PendingIntent.CanceledExceptionThrows CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.
cancel()函數(shù)

public void cancel ()

Since: API Level 1

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

只有PengdingIntent的原應(yīng)用程序才能調(diào)用cancel()來把它從系統(tǒng)中移除掉。

getTargetPackage()函數(shù)

public String getTargetPackage ()

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.

posted on 2012-03-15 22:22 life02 閱讀(1894) 評論(0)  編輯 收藏 引用 所屬分類: Android開發(fā)
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            久久国产一区二区三区| 一区二区三区色| 亚洲综合首页| 午夜久久资源| 久久久久久综合网天天| 黄色日韩网站视频| 开心色5月久久精品| 亚洲第一网站| 久久久综合香蕉尹人综合网| 免费高清在线视频一区·| 伊人夜夜躁av伊人久久| 久久影院午夜论| 在线观看欧美视频| 曰本成人黄色| 亚洲欧洲日产国产综合网| 欧美久久电影| 亚洲欧美日韩精品在线| 欧美好骚综合网| 亚洲一区久久久| 久久er精品视频| 亚洲精品在线三区| 国内精品久久国产| 日韩系列欧美系列| 欧美一区综合| 中日韩男男gay无套| 国内偷自视频区视频综合| 一区二区三区在线视频免费观看| 欧美日韩高清在线| 欧美在线播放一区| 一本色道久久综合狠狠躁篇怎么玩| 久久成人18免费网站| 乱码第一页成人| 欧美主播一区二区三区美女 久久精品人 | 欧美日韩成人综合在线一区二区| 亚洲一区二区免费看| 亚洲国产欧美久久| 久久久久国产精品一区| 亚洲一区欧美二区| 另类综合日韩欧美亚洲| 在线一区日本视频| 中国女人久久久| 久久一区二区视频| 久久国产成人| 欧美午夜视频在线| 欧美午夜一区二区| 亚洲国产成人91精品| 亚洲国产精品久久久久秋霞不卡| 亚洲欧美日韩中文在线制服| 亚洲国内精品| 久久久久综合| 国产亚洲一区在线| 国外视频精品毛片| 亚洲欧美日韩成人| 亚洲美女电影在线| 在线一区二区三区四区五区| 欧美77777| 欧美电影免费观看高清| 牛牛国产精品| 依依成人综合视频| 久久久久一区二区三区| 亚洲欧美日韩一区| 欧美色欧美亚洲另类二区| 欧美午夜欧美| 99视频一区| 亚洲一区二区综合| 亚洲美女在线看| 欧美日韩免费高清| 国产亚洲日本欧美韩国| 国产精品一级| 国产亚洲综合在线| 性欧美超级视频| 久久gogo国模啪啪人体图| 国产精品99久久99久久久二8| 欧美日韩精品一区二区天天拍小说| 亚洲六月丁香色婷婷综合久久| 欧美激情中文字幕一区二区| 欧美激情一区三区| 国产日韩欧美高清| 91久久精品日日躁夜夜躁国产| 欧美 日韩 国产在线| 欧美激情视频一区二区三区不卡| 久久精品视频在线播放| 欧美高清一区| 国产精品二区在线| 狠狠色狠色综合曰曰| 久久综合综合久久综合| 嫩草国产精品入口| 亚洲综合久久久久| 久久精品二区| 99视频精品免费观看| 亚洲天堂av图片| 欧美a级片一区| 亚洲天堂第二页| 亚洲欧美在线一区二区| 激情综合五月天| 亚洲人被黑人高潮完整版| 欧美在线视频免费观看| 亚洲第一级黄色片| 午夜电影亚洲| 欧美国产第二页| 亚洲女人天堂成人av在线| 久久综合国产精品台湾中文娱乐网| 亚洲电影在线| 亚洲黄色在线| 久久综合影音| 亚洲欧美日韩人成在线播放| 久久一二三四| 午夜综合激情| 欧美激情综合五月色丁香小说| 性刺激综合网| 欧美精品一区二区在线观看| 久久亚洲一区二区三区四区| 欧美日韩国产一级片| 老鸭窝91久久精品色噜噜导演| 欧美视频三区在线播放| 久久综合一区二区| 国产精品美女久久久久aⅴ国产馆| 一区二区久久| 久久久精品一区二区三区| 正在播放亚洲一区| 另类欧美日韩国产在线| 欧美专区第一页| 国产精品福利在线观看| 亚洲激情第一区| 亚洲国产精品成人va在线观看| 亚洲男人的天堂在线| 亚洲欧美日韩精品久久奇米色影视 | 日韩午夜剧场| 亚洲黄色影片| 可以看av的网站久久看| 国产精品午夜视频| 久久精品久久综合| 亚洲尤物在线视频观看| 一本色道久久88亚洲综合88| 麻豆精品在线视频| 亚洲精品中文字幕有码专区| 久久久99精品免费观看不卡| 欧美主播一区二区三区美女 久久精品人| 欧美日韩免费观看一区| 亚洲精品你懂的| 一区二区欧美在线| 欧美日韩妖精视频| 夜夜狂射影院欧美极品| 国产精品一区二区三区久久久| 一本到12不卡视频在线dvd| 中文亚洲视频在线| 国产精品chinese| 亚洲女与黑人做爰| 久久精品国产亚洲高清剧情介绍| 国产欧美日韩综合一区在线播放 | 午夜精品久久久久久久99水蜜桃 | 亚洲成在线观看| 欧美成人免费网| 99国产精品久久久久老师| 亚洲一区二区三区中文字幕| 久久国产精品久久久久久电车 | 一本一本久久| 亚洲综合日韩| 黄色日韩网站视频| 欧美日韩国产欧| 亚洲综合不卡| 欧美 日韩 国产在线| 一本色道久久综合精品竹菊| 国产精品久久久久久亚洲调教| 午夜一区不卡| 亚洲国产成人av在线| 亚洲天堂av高清| 国产性天天综合网| 嫩草成人www欧美| 亚洲制服av| 亚洲第一区在线观看| 亚洲欧美激情一区| 亚洲福利在线视频| 国产精品多人| 老司机免费视频一区二区| 亚洲美女精品一区| 久久免费国产| 亚洲欧美日韩国产综合| 亚洲国产一成人久久精品| 欧美体内谢she精2性欧美| 久久成人久久爱| 这里只有精品视频| 欧美+日本+国产+在线a∨观看| 亚洲女人天堂成人av在线| 亚洲国内精品在线| 国内精品美女在线观看| 欧美日韩一级大片网址| 美女网站久久| 久久免费高清| 久久国产福利国产秒拍| 在线视频一区观看| 美女任你摸久久| 欧美主播一区二区三区| 亚洲一区二区高清| 亚洲免费精品| 亚洲另类自拍| 亚洲最黄网站| 一区二区三区免费在线观看| 亚洲美女视频网| 亚洲风情亚aⅴ在线发布|