【问题标题】:Resuming current background activity on notification在通知上恢复当前后台活动
【发布时间】:2014-11-19 18:04:24
【问题描述】:

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

    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());

如果我的活动在后台,我想要,并且用户点击通知应用程序恢复当前在后台的活动并显示对话框。 如果我的申请已关闭。打开 Launching 活动,然后显示对话框。

【问题讨论】:

    标签: java android


    【解决方案1】:

    如果您想在单击通知时再次继续(在这种情况下您的应用程序仍在后台运行),则可以使用此方法: http://developer.android.com/training/basics/activity-lifecycle/stopping.html

    我试过了,效果很好。

    【讨论】:

      【解决方案2】:

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

      要跟踪您在 backstack 上的活动,请使用此How to know Activity Count of my application? 建议。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-30
        • 2016-12-15
        • 1970-01-01
        相关资源
        最近更新 更多