Java 在收到通知时恢复当前后台活动

Java 在收到通知时恢复当前后台活动,java,android,Java,Android,我的应用程序包含多个活动。我已经实现了推送通知,并在工具栏中显示了通知。我的问题是,当我点击通知时,会将我带到我指定的特定活动 Intent intent =new Intent(GcmService.this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(GcmService.this, 0, intent, 0); NotificationCompat.B

我的应用程序包含多个活动。我已经实现了推送通知,并在工具栏中显示了通知。我的问题是,当我点击通知时,会将我带到我指定的特定活动

    Intent intent =new Intent(GcmService.this, MainActivity.class);

    PendingIntent pendingIntent = PendingIntent.getActivity(GcmService.this, 0, intent, 0);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
            getApplicationContext())
            .setContentTitle(getResources().getString(R.string.app_name))
            .setAutoCancel(true)
            .setContentIntent(pendingIntent);

    notificationBuilder.setContentIntent(pendingIntent);
    mNotificationManager.notify((int) when, notificationBuilder.build());
我想知道我的活动是否在后台,用户单击通知应用程序恢复后台的当前活动并显示对话框。
如果我的申请被关闭。打开启动活动,然后显示对话框。

如果要在单击通知时再次继续,在这种情况下,应用程序仍在后台运行,则可以使用此方法:


我已经尝试过了,而且效果很好。

您可以将通知链接到DispatcherActivity。 如果后台有打开的活动,请在onCreate中突然完成DispatcherActivity。如果没有,请转到您的启动活动并完成DispatcherActivity

要跟踪您在backbackback上的活动,请使用以下建议