2012-02-24 79 views
0

我有一个应用程序通过某种提醒来提醒用户。这些提醒显示为通知。当用户点击任何这些通知时,它应该显示关于该警报的附加信息。这基本上是通过调用具有特定参数的活动来完成的。单击“通知”图标时只显示一次活动

这是我做的:

NotificationManager mNotificationManager = (NotificationManager) MyApplication.getContext().getSystemService(Context.NOTIFICATION_SERVICE);     
Notification notification = new Notification(R.drawable.reminder2, reminder.Title, System.currentTimeMillis()); 

Intent notificationIntent = null; 
notificationIntent = new Intent(MyApplication.getContext(), ReminderActivity.class); 
notificationIntent.putExtra("idnotification", reminder.ID); 


PendingIntent contentIntent = PendingIntent.getActivity(MyApplication.getContext(), reminder.ID, notificationIntent, 0); 

notification.defaults |= Notification.DEFAULT_SOUND; 
notification.defaults |= Notification.DEFAULT_VIBRATE; 
notification.defaults |= Notification.DEFAULT_LIGHTS; 
notification.defaults |= Notification.FLAG_INSISTENT; 


notification.setLatestEventInfo(MyApplication.getContext(), "Reminder", reminder.Title, contentIntent); 

mNotificationManager.notify(reminder.ID, notification); 

这似乎是工作,但问题是,如果我点击一个通知一个以上的时间它会创建一个新的活动,而不是显示一个已经可见。

我试着为PendingIntent设置标志,但没有运气。我试着用FLAG_CANCEL_CURRENT,FLAG_NO_CREATE,FLAG_ONE_SHOT,FLAG_UPDATE_CURRENT。唯一一个接近我需要的是FLAG_ONE_SHOT,但第二次点击它并不显示活动。

我还能试试吗?我在这里完全没有想法。 谢谢

回答

1

Manifest设置launchModeActivitysingleTop。如果这不起作用,请尝试singleInstance。我认为其中之一可能更适合你。

如果这不起作用,尝试用一些标志搞乱了Intent

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)

我会尝试以下标志来看看有什么效果,甚至使用超过一个:

FLAG_ACTIVITY_CLEAR_TOP 
FLAG_ACTIVITY_RESET_TASK_IF_NEEDED 
FLAG_ACTIVITY_CLEAR_TASK 
FLAG_ACTIVITY_NEW_TASK (in conjunction with others) 

你可以看到更多细节上的所有标志here(下总结,Contstants ......然后所有以FLAG_ACTIVITY启动标志)。如果我的建议不起作用,我认为您仍然可以在文档中找到您的答案。

+0

感谢您的回复。我仍然无法实现它,我对尝试组合和组合以及在这个问题上花费时间感到厌倦。我想我会在用户点击时从状态栏中删除通知。问候 – LEM 2012-02-27 00:48:50