WEB开发网
开发学院手机开发Android 开发 一个Android SDK文档PendingIntent的问题 阅读

一个Android SDK文档PendingIntent的问题

 2010-06-22 02:13:00 来源:WEB开发网   
核心提示:发现了一个PendingIntent的一个问题,在SDK文档对几个API描述如下:public static PendingIntent getActivity (Context context, int requestCode, Intent intent, int flags)Since: API Level 1R

发现了一个PendingIntent的一个问题,在SDK文档对几个API描述如下:

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

Since: API Level 1Retrieve 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.

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_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, or any of the flags as supported by Intent.fillIn() to control which unspecified parts of the intent that can be supplied when the actual send happens.

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 getBroadcast (Context context, int requestCode, Intent intent, int flags)

Since: API Level 1Retrieve 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_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, or any of the flags as supported by Intent.fillIn() to control which unspecified parts of the intent that can be supplied when the actual send happens.

Returns

Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.

请看 requestCode参数,这里注明了这个参数当前并不使用,实际上这个参数是有用的,当通知同时有很多个的时候,必须指定这个参数来达到唯一识别的效果,仅仅通过notification.notify(id, n);来指定ID是不够的,这样仅能在通知栏上显示唯一,具体点进去的时候使用的intent会是最后一个被加进去的intent.

大家一定注意!!!

Tags:一个 Android SDK

编辑录入:coldstar [复制链接] [打 印]
赞助商链接