2012-03-27 137 views
0

我從服務發送一個通知,其中包含Parcelable ArrayList的內容。Android中的服務:通過通知在服務和活動之間的Parcelable ArrayList

//my service code 
Intent intent = new Intent(mContext, AutoSearchActivity.class); 

//In this list, there is 3 elements 
intent.putParcelableArrayListExtra(Staff.JSON_ARRAY,staffs); 

PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent , 0); 

Notification notification = new Notification(
    R.drawable.toplogo, 
    (String) getResources().getString(R.string.notification), 
    System.currentTimeMillis()); 

String titleNotification = (String) getResources().getString(R.string.notification_title); 

String textNotification = (String) getResources().getString(R.string.notification_content); 

notification.setLatestEventInfo(mContext, titleNotification,textNotification, pendingIntent); 

notification.vibrate = new long[] { 0, 400, 100, 400, 100, 600 }; 

notificationManager.notify(ID_NOTIFICATION, notification); 

在登錄我的通知後,執行AutoSearchActivity。我嘗試捕獲數據並顯示它們,但只顯示舊數據。我想有一種緩存系統,但我不知道如何刪除它。

//in my AutoSearchActivity 
Bundle bundle = getIntent().getExtras(); 

//only 1 element !!! 
ArrayList<SiteStaff> listAppInfo = bundle.getParcelableArrayList(Staff.JSON_ARRAY); 

謝謝你的幫忙!

回答

4

是的,Pending Intent被緩存,產生了很多問題。將您的行更改爲 PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent , PendingIntent.FLAG_UPDATE_CURRENT);以強制待定意圖採取唯一最新值,即使它被多次觸發。

+1

謝謝我的朋友〜它的作品!我第一次聽說有關意向問題〜謝謝! – johann 2012-03-27 09:54:22

+0

歡迎您:) – Akhil 2012-03-27 10:04:27