2
我的目标:并行下载文件,当文件下载完成时,我收到通知。通过通知向pendingIntent发送不同的参数
这些通知是假设启动一个活动,当你点击它,通过putExtra
得到独特的参数。
问题是,我不能在每次启动该活动时使用不同的值。
每次通过通知栏启动的活动都会销毁尚未启动的活动(即仍在通知栏上显示的活动)的活动。
如何使用自己的参数保留所有通知?
这里是我的代码:
if (messagesManager == null)
{
messagesManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
}
notification = new Notification(R.drawable.icon, message, System.currentTimeMillis());
// for launch activity
Intent intent = new Intent(context, DialogActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("fileName", fileName); //- this is where i put my extra's!!
intent.putExtra("onSdcard", onSdcard);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, "DownloadManager", message, contentIntent);
notification.flags = notification.FLAG_AUTO_CANCEL;
int noticeId = generateNotificationId(requestId);
messagesManager.notify(noticeId, notification);
现在,这是对话活动:
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Intent i = getIntent();
boolean onSdcard = i.getBooleanExtra("onSdcard", true);
String fileName = i.getStringExtra("fileName");
...
}
我想,因为它是写在这里另一篇文章中使用这种技术,但事实并非如此工作。
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
可能重复的[Android持续缓存我的意图额外,如何申报一个待定的意图,保持新鲜的额外?](http://stackoverflow.com/questions/3140072/android-keeps-caching-my-intents-extras-how-to-declare-a-pending-intent-that-kee) – Pentium10 2010-07-06 14:55:09