我从服务发送一个内容为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);
感谢您的帮助!
答案 0 :(得分:4)
是的,Pending Intent被缓存,会产生很多问题。将您的行更改为
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent , PendingIntent.FLAG_UPDATE_CURRENT);
强制Pending意图获取唯一的最新值,即使它被多次触发。