所以我目前正在显示通知.当用户单击此注释时,将启动该应用程序.通知仍然存在,表示该服务正在后台运行.
Intent notificationIntent = new Intent(context, LaunchActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(1, notification);
Run Code Online (Sandbox Code Playgroud)
但是,我发现了一个出现错误的情况.如果用户通过单击正常图标启动应用程序,并且在活动正在运行时单击通知,则会启动新活动,而不会退出先前的活动,后者位于较早的活动之上.这还不是全部:进一步点击通知将创建其他活动并将其置于已经运行的活动之上.我怎么能阻止这个?是否有一个很好的检查,以查看某个活动当前是否正在显示或已加载?
android ×1