【问题标题】:Navigating push notification will close intermediate activity when back press navigated activity android导航推送通知将在按下导航活动android时关闭中间活动
【发布时间】:2017-01-28 04:46:03
【问题描述】:

单击推送通知时,我正在导航到活动 C。活动 A 是我的主屏幕,我目前在活动 A 的活动 B 中,同时收到推送通知。现在考虑我正在接收推送通知并单击收到的通知。单击推送通知活动 C 后加载。然后我回来按我的应用程序,这将关闭中间活动 B。但我不想关闭我的中间活动。

我对活动 A 的待定意图如下所示,

  Intent intent = new Intent(context, A.class);
     intent.putExtra(PUSH_MESSAGE, notification);
     PendingIntent.getActivity(context, previousId + 1, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

清单文件如下所示,

<activity
        android:name=".A"
        android:configChanges="orientation|keyboard|screenSize"
        android:screenOrientation="portrait"
        android:launchMode="singleTask"
        android:theme="@style/AppTheme.Light.NoActionBar"/>
<activity
        android:name=".B"
        android:configChanges="orientation"
        android:launchMode="singleTop"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.Light.NoActionBar" />
<activity
        android:name=".C"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:theme="@style/Theme.Overlay"/>

我也正在从活动 A 启动活动 B,如下所示,

Intent intent = new Intent(getContext(), B.class);
getContext().startActivity(intent);

并在单击收到的推送通知时启动 Activity C,如下所示,

 Intent intent = new Intent(context, C.class);
 intent.putExtra(C.IS_FROM_PUSH_NOTIFICATION, true);
 ((Activity) context).startActivityForResult(intent, REQUEST_CODE_REFRESH);

您能建议我这样做吗?

【问题讨论】:

  • 请解释您如何通过推送通知使用startActivityForResult() 启动C。这没有意义。
  • A是如何启动的(使用PendingIntent)?什么启动了 A?

标签: android android-activity android-manifest android-pendingintent


【解决方案1】:

在 manifest.xml 中进行以下更改

<activity
        android:parentActivityName=".B"
        android:name=".C"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:theme="@style/Theme.Overlay"/>

【讨论】:

  • 感谢您的回复。我不仅将 B 作为中间活动。我有 n 个像 B 这样的中间活动。我想我不能这样使用。
猜你喜欢
  • 2021-06-07
  • 1970-01-01
  • 2011-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多