【发布时间】:2010-07-06 14:44:47
【问题描述】:
我的目标:并行下载文件,当文件下载完成时,我会收到通知。
这些通知应该会在您单击它时启动一个活动,该活动通过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 android-notifications