0

我将活动接收器设置为通知的内容意图。

Intent clickIntent = new Intent(context, Receiver.class);
            mBuilder.setContentIntent(PendingIntent.getActivity(context, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT));

在 Receiver Activity 中,我正在启动旨在通过以下方式使用 TaskStackBuilder 打开的活动。

Intent intent = new Intent(this, Class.forName(className));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
       TaskStackBuilder.create(this).addParentStack(Class.forName(className)).addNextIntent(intent).startActivities();

当应用程序在后台并且发生通知点击时,它会恢复 ParentActivity。特别是当设备进入空闲状态并返回时。有什么帮助吗?我对此很头疼。

4

1 回答 1

0

对于Android 应用程序,您还应该android:launchMode在 androidManifest.xml 文件中声明。

Android 文档中所述:

关于如何启动活动的说明。有四种模式与Intent对象中的活动标志(FLAG_ACTIVITY_* 常量)一起工作,以确定当调用活动来处理意图时应该发生什么。

他们是:

  • “标准”
  • “单顶”
  • “单任务”
  • “单一实例”

默认模式是“标准”。

此 SO 帖子中给出的解决方案 -从通知中恢复活动也可能会有所帮助。

于 2016-07-21T10:45:42.113 回答