-
<activity android:name="SkyfileActivity" - android:launchMode="singleTask" />
- PendingIntent contentIntentBegin = PendingIntent.getActivity(
- notificationContext, 0, inStart, PendingIntent.FLAG_UPDATE_CURRENT);
最后一个参数就是 FLAG,这个FLAG 的 意思就是:如果系统中已存在该PendingIntent对象,那么系统将保留该PendingIntent对象,但是会使用新的Intent来更新之前PendingIntent中的Intent对象数据,例如更新Intent中的Extras。这个非常有用,例如之前提到的,我们需要在每次更新之后更新Intent中的Extras数据,达到在不同时机传递给MainActivity不同的参数,实现不同的效果。
就是 Intent里边的数据没更新而已, 很2个问题 搞了很久 才发现原来加个FLAG 就行了,有点伤不起了。!!

代码片段
- public void showNotiMessageBegin(String message, int requestCode,
- String itemid) {
- notification = new Notification(R.drawable.skyfile_upload_noti,
- message, System.currentTimeMillis());
- if (requestCode == 1 && notification.contentIntent == null) {
- int index = itemid.lastIndexOf("/");
- final String backPath1 = itemid
- .substring(0, index == 0 ? 1 : index);
- Intent inStart = new Intent(notificationContext, SkyfileActivity.class);
- inStart.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- inStart.setData(Uri.parse(MetaDataView.class.getName()));
- inStart.putExtra(MetaDataView.BUNDLE_PATH, backPath1);
- PendingIntent contentIntentBegin = PendingIntent.getActivity(
- notificationContext, 0, inStart, PendingIntent.FLAG_UPDATE_CURRENT);
- notification.contentIntent = contentIntentBegin;
- notification.flags |= Notification.FLAG_AUTO_CANCEL;
- notification.setLatestEventInfo(notificationContext,
- UPLOATTITLE, message, contentIntentBegin);
- notificationMgr.notify(1, notification);
- } else {
- notification.contentIntent.cancel();
- }
- }
更多关于PengingIntent 的 大家可以看看 这里。 http://www.7dot9.com/2011/04/android-pendingintent%E7%9A%84%E4%B8%80%E4%BA%9B%E5%B0%8F%E8%BF%B7%E6%83%91/