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

life02

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

PendingIntent詳解 

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

2011-08-05 10:13:04|  分類: Android基礎 |  標簽: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)系列方法從系統取得一個用于啟動一個Activity的PendingIntent對象,
可以通過getService(Context context, int requestCode, Intent intent, int flags)方法從系統取得一個用于啟動一個Service的PendingIntent對象
可以通過getBroadcast(Context context, int requestCode, Intent intent, int flags)方法從系統取得一個用于向BroadcastReceiver的Intent廣播的PendingIntent對象
返回的PendingIntent可以遞交給別的應用程序,然后繼續處理。這里的話你可以稍后才處理PendingIntent中描述的Intent及其最終行為。
當你把PendingIntent遞交給別的程序進行處理時,PendingIntent仍然擁有PendingIntent原程序所擁有的權限(with the same permissions and identity).當你從系統取得一個PendingIntent時,一定要非常小心才行。比如,通常,如果Intent目的地是你自己的component(Activity/Service/BroadcastReceiver)的話,你最好采用在Intent中顯示指定目的component名字的方式,以確保Intent最終能發到目的,否則Intent最后可能不知道發到哪里了。一個PendingIntent就是Android系統中的一個token(節點,這個應該是Linux或C\C++用語)的一個對象引用,它描述了一些將用于retrieve的數據(這里,這些數據描述了Intent及其最終的行為)。
這就意味著即使PendingIntent原進程結束了的話, PendingIntent本身仍然還存在,可在其他進程(PendingIntent被遞交到的其他程序)中繼續使用.如果我在從系統中提取一個PendingIntent的,而系統中有一個和你描述的PendingIntent對等的PendingInent, 那么系統會直接返回和該PendingIntent其實是同一token的PendingIntent,而不是一個新的token和PendingIntent。然而你在從提取PendingIntent時,通過FLAG_CANCEL_CURRENT參數,讓這個老PendingIntent的先cancel()掉,這樣得到的pendingInten和其token的就是新的了。
通過FLAG_UPDATE_CURRENT參數的話,可以讓新的Intent會更新之前PendingIntent中的Intent對象數據,例如更新Intent中的Extras。另外,我們也可以在PendingIntent的原進程中調用PendingIntent的cancel ()把其從系統中移除掉。
注意:兩個PendingIntent對等是指它們的operation一樣, 且其它們的Intent的action, data, categories, components和flags都一樣。但是它們的Intent的Extra可以不一樣。
主要常量
FLAG_CANCEL_CURRENT:如果當前系統中已經存在一個相同的PendingIntent對象,那么就將先將已有的PendingIntent取消,然后重新生成一個PendingIntent對象。
FLAG_NO_CREATE:如果當前系統中不存在相同的PendingIntent對象,系統將不會創建該PendingIntent對象而是直接返回null。
FLAG_ONE_SHOT:該PendingIntent只作用一次。在該PendingIntent對象通過send()方法觸發過后,PendingIntent將自動調用cancel()進行銷毀,那么如果你再調用send()方法的話,系統將會返回一個SendIntentException。
FLAG_UPDATE_CURRENT:如果系統中有一個和你描述的PendingIntent對等的PendingInent,那么系統將使用該PendingIntent對象,但是會使用新的Intent來更新之前PendingIntent中的Intent對象數據,例如更新Intent中的Extras。
主要成員函數
getActivities系列方法
該系列方法將從系統取得一個用于啟動一個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)中調用,那么必須對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的某個數據項可以被send方法的Inent參數進行覆蓋重寫。
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的數據項可以被send方法的Intent參數覆蓋重寫。
Returns
  • Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.
getService方法
該方法將系統取得一個用于啟動一個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的數據項可以被send方法的Intent參數覆蓋重寫。
Returns
  • Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.
getBroadcast方法
該方法將從系統取得一個用于向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的數據項可以被send方法的Intent參數覆蓋重寫。
Returns
  • Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.
send系列方
該系列主要用于觸發PendingIntent的Intent行為。用其Intent或啟動一個Activity,或啟動一個Service,或向BroadcastReceiver發送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.
該參數是因為intent參數才需要提供的,所用如果你的intent參數不為null的話,該參數也不能為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.
通過該參數,我們可以設置在Intent發送成功后的回調函數。
handlerHandler 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.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.
該參數是因為intent參數才需要提供的,一般是當前的context,如果你的intent參數不為null的話,該函數也不能為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.
通過該參數,我們可以指定Intent發送成功后的回調函數。
handlerHandler 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.CanceledExceptionThrows CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.
cancel()函數

public void cancel ()

Since: API Level 1

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

只有PengdingIntent的原應用程序才能調用cancel()來把它從系統中移除掉。

getTargetPackage()函數

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 閱讀(1897) 評論(0)  編輯 收藏 引用 所屬分類: Android開發
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            国产精品h在线观看| 欧美女人交a| 国产亚洲精品高潮| 亚洲午夜av| 亚洲图片欧洲图片日韩av| 国内精品久久国产| 欧美中文在线免费| 亚洲一区三区视频在线观看 | 美女精品在线观看| 性色av一区二区怡红| 国产精品久久久久久亚洲调教| 一区二区三区四区五区在线| 欧美高清视频免费观看| 久久亚洲高清| 亚洲国产一区二区a毛片| 亚洲第一页中文字幕| 午夜精品久久久| 亚洲午夜电影| 欧美三级午夜理伦三级中文幕| 午夜精品美女自拍福到在线| 国产日韩欧美a| 免费一级欧美片在线播放| 国产精品久久久久久模特| 亚洲毛片在线观看| 国产精品九色蝌蚪自拍| 久久伊人免费视频| 欧美寡妇偷汉性猛交| 亚洲视频在线二区| 午夜视频一区二区| 先锋影音网一区二区| 麻豆九一精品爱看视频在线观看免费| 亚洲精品男同| 小处雏高清一区二区三区| 性欧美长视频| 国产欧美视频一区二区三区| 蜜桃伊人久久| 亚洲高清网站| 亚洲免费在线观看| 亚洲精品黄色| 欧美久久影院| 亚洲午夜精品17c| 欧美一区二区精品久久911| 模特精品裸拍一区| 久久xxxx| 激情亚洲网站| 亚洲一区二区三区免费视频| 欧美一区二区高清| 伊人精品久久久久7777| 亚洲视频中文| 久久精品电影| 国产精品国产一区二区| 亚洲欧美日韩成人| 另类图片国产| 国产亚洲欧美另类中文| 久久综合成人精品亚洲另类欧美| 久久精品电影| 亚洲人精品午夜在线观看| 欧美在线三区| 亚洲专区国产精品| 欧美激情一区二区三区| 美国成人直播| 日韩天堂av| 欧美高清一区二区| 亚洲字幕在线观看| 欧美成人精品激情在线观看| 影音先锋久久资源网| 欧美理论电影在线观看| 香蕉久久夜色精品国产| 亚洲高清一二三区| 欧美一级一区| 亚洲最新合集| 欧美精品自拍偷拍动漫精品| 亚洲欧美国产不卡| 亚洲国产精品视频| 亚洲人成在线观看一区二区| 国产精品久久久久久久久搜平片 | 欧美激情中文字幕在线| 韩国成人精品a∨在线观看| 亚洲男同1069视频| 亚洲高清免费视频| 久久久久久久尹人综合网亚洲 | 一区二区三区.www| 狠狠色综合播放一区二区| 欧美日韩在线一区二区| 久久久亚洲成人| 你懂的视频欧美| 西西人体一区二区| 宅男噜噜噜66一区二区| 亚洲日本欧美日韩高观看| 国产日本欧美在线观看| 国产精品啊啊啊| 欧美激情中文字幕一区二区| 久久综合久久综合久久| 久久成人精品视频| 亚洲成人在线视频播放| 日韩午夜av| 亚洲国产成人高清精品| 国产视频一区二区在线观看| 国产精品久久久久久久久免费樱桃| 欧美国产精品日韩| 蜜桃av一区二区三区| 久久久久五月天| 欧美在线免费播放| 久久国产精品一区二区三区四区 | 国产精品日本| 久久久xxx| 亚洲欧洲一区二区在线播放| 亚洲一区免费看| 一区二区三区欧美| 99爱精品视频| 中国成人在线视频| 亚洲少妇中出一区| 亚洲一区二区三区精品在线观看| 国产一区二区丝袜高跟鞋图片| 国产乱码精品| 欧美电影美腿模特1979在线看| 亚洲婷婷综合色高清在线| 99在线精品免费视频九九视| 久久福利视频导航| 久久爱www.| 久久一区中文字幕| 欧美不卡一卡二卡免费版| 欧美激情va永久在线播放| 欧美激情一区二区久久久| 亚洲国产精品视频| 99视频精品| 亚洲欧美视频| 久久综合久久美利坚合众国| 欧美福利一区| 国产精品夫妻自拍| 国产自产高清不卡| 亚洲成色www久久网站| 国产精品久线观看视频| 国产美女精品在线| 在线欧美日韩国产| 一卡二卡3卡四卡高清精品视频 | 一区二区三区精品视频在线观看| 国产精品99久久久久久人| 欧美影院午夜播放| 欧美国产日韩一区| 在线视频精品一| 欧美福利精品| 一区二区日韩| 亚洲人线精品午夜| 欧美大香线蕉线伊人久久国产精品| 欧美激情欧美激情在线五月| 日韩亚洲国产精品| 亚洲人成网站777色婷婷| 中文国产亚洲喷潮| 久久久免费精品| 欧美日韩一区免费| 欧美激情五月| 国产亚洲一本大道中文在线| 亚洲高清视频的网址| 亚洲欧美视频一区| 欧美电影在线观看完整版| 在线视频日本亚洲性| 久久午夜精品一区二区| 国产精品久久久久久久久久免费 | 模特精品裸拍一区| 中文精品视频一区二区在线观看| 久久久久在线| 国产精品天美传媒入口| 日韩午夜在线视频| 免费观看一区| 欧美一区二区免费| 久久成人免费日本黄色| 欧美色网一区二区| 亚洲国产一区二区三区青草影视| 欧美一区二区三区视频| 亚洲伦伦在线| 欧美国产91| 亚洲国产欧美日韩精品| 久久九九热免费视频| 亚洲一二三区在线观看| 欧美伦理影院| 亚洲精品视频在线观看免费| 久久在线免费观看| 性久久久久久久| 国产美女诱惑一区二区| 亚洲伊人伊色伊影伊综合网| 最新日韩在线视频| 免费视频最近日韩| 亚洲国产精品黑人久久久| 玖玖国产精品视频| 久久精品夜夜夜夜久久| 国产亚洲欧美日韩一区二区| 午夜一级久久| 亚洲欧美日韩中文在线制服| 国产精品久久一卡二卡| 亚洲男人的天堂在线| 嫩草国产精品入口| 久久久美女艺术照精彩视频福利播放| 国产精品系列在线播放| 午夜欧美精品久久久久久久| 制服诱惑一区二区| 国产精品视频一二| 久久精品一区中文字幕| 欧美在线视屏| 亚洲国产精品传媒在线观看 |