Android 通知栏的单击事件
单击通知栏时,它将跳过Android 通知栏的单击事件,android,notifications,Android,Notifications,单击通知栏时,它将跳过MainActivity.class界面: Intent notificationIntent = new Intent(context,MainActivity.class); //After click the notification, it will skip to the activity PendingIntent contentIntent = PendingIntent.getActivity(context,0,notificationIntent,0)
MainActivity.class
界面:
Intent notificationIntent = new Intent(context,MainActivity.class); //After click the notification, it will skip to the activity
PendingIntent contentIntent = PendingIntent.getActivity(context,0,notificationIntent,0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
如果MainActivity.class
本身已经打开,我再次单击通知栏,它会显示两个界面。谁知道如何解决这个问题 更改您的线路:
Intent notificationIntent = new Intent(context,MainActivity.class);
致:
从Android文档中可以看出:
如果已设置,则如果活动已在历史堆栈顶部运行,则不会启动该活动 或者,如果这不是预期的行为,请检查此标志:
如果已设置,并且正在启动的活动已在当前任务中运行,则不会启动该活动的新实例,而是关闭其上的所有其他活动,并且此意图将作为新意图传递给(现在位于顶部的)旧活动 当您试图了解这些标志将导致什么时,您可能会对以下文档感兴趣:
- (特别是第节)
Intent notificationIntent =
new Intent(context,MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);