-
<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/