標籤:android blog io os 使用 java ar 資料 div
Intent updateIntent = new Intent(GetNoticeService.this,DetailGonggaoActivity.class);updateIntent.putExtra("type", "weidu");updateIntent.putExtra("title",(String) json.get("title"));updateIntent.putExtra("id", json.get("noticeid").toString());//加上這句就不會出現同一個activity出現多次的情況了updateIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);//下面有對個參數,是設定的關鍵PendingIntent updatePendingIntent = PendingIntent.getActivity(GetNoticeService.this, i, updateIntent,PendingIntent.FLAG_UPDATE_CURRENT);Notification updateNotification = new Notification();// 設定通知欄顯示內容updateNotification.icon = R.drawable.logo;updateNotification.flags |= updateNotification.FLAG_AUTO_CANCEL;updateNotification.tickerText = "外勤精靈發來新的公告通知";updateNotification.defaults = Notification.DEFAULT_SOUND;// 鈴聲提醒updateNotification.setLatestEventInfo(GetNoticeService.this,"外勤精靈發來新的公告通知", (String) json.get("title"),updatePendingIntent);updateNotificationManager.notify(i, updateNotification);
//加上這句就不會出現同一個activity出現多次的情況了,不解釋updateIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
updateNotificationManager.notify(i, updateNotification);這句傳遞的i標記了updateNotification的位置和id相同的時候就覆蓋原來的updateNotification,所以要傳遞不同的id,使不同的updateNotification不覆蓋。
PendingIntent updatePendingIntent = PendingIntent.getActivity(GetNoticeService.this, i, updateIntent,PendingIntent.FLAG_UPDATE_CURRENT);Notification updateNotification = new Notification();
flags有四個取值:
int FLAG_CANCEL_CURRENT:如果該PendingIntent已經存在,則在產生新的之前取消當前的。
int FLAG_NO_CREATE:如果該PendingIntent不存在,直接返回null而不是建立一個PendingIntent.
int FLAG_ONE_SHOT:該PendingIntent只能用一次,在send()方法執行後,自動取消。
int FLAG_UPDATE_CURRENT:如果該PendingIntent已經存在,則用新傳入的Intent更新當前的資料。
我們需要把最後一個參數改為PendingIntent.FLAG_UPDATE_CURRENT,這樣在啟動的Activity裡就可以用接收Intent傳送資料的方法正常接收。
前面的id作用一樣
android PendingIntent 使用通知傳遞多個參數,及不覆蓋的問題