Android 单击通知时清除所有堆栈
我在android应用程序上使用FCM显示通知。除一个问题外,一切正常 当用户单击通知时,我需要关闭应用程序的所有后台和前台活动,并打开通知中指定的意图 我怎么做 我正在使用这样的待定意图Android 单击通知时清除所有堆栈,android,firebase,android-notifications,firebase-cloud-messaging,Android,Firebase,Android Notifications,Firebase Cloud Messaging,我在android应用程序上使用FCM显示通知。除一个问题外,一切正常 当用户单击通知时,我需要关闭应用程序的所有后台和前台活动,并打开通知中指定的意图 我怎么做 我正在使用这样的待定意图 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); final PendingIntent resultPendingIntent = Pendin
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
final PendingIntent resultPendingIntent =
PendingIntent.getActivity(
mContext,
0,
intent,
PendingIntent.FLAG_CANCEL_CURRENT
);
可以使用2个标志清除所有堆栈
intentToLaunch.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intentToLaunch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
可以使用2个标志清除所有堆栈
intentToLaunch.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intentToLaunch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
试试这个
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
Intent notificationIntent = new Intent(context, HomeActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
试试这个
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
Intent notificationIntent = new Intent(context, HomeActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);