android - 需要在后按的android上打开家庭活动
问题描述
在正常情况下,我有一个活动堆栈是 A -> B -> C,当我收到推送通知并实施 click_action 时,它会打开正确的活动 C。
现在,需要的是当活动 C 在按下后退按钮后从推送通知打开时,它会关闭并且整个应用程序进入后台,但我需要导航到主屏幕(活动 A)
<activity
android:name="Activity_A"
android:exported="false"
android:screenOrientation="sensorPortrait"
android:theme="@style/MyAppTheme"
android:windowSoftInputMode="stateHidden|adjustResize" />
<activity
android:name="Activity_B"
android:exported="false"
android:screenOrientation="sensorPortrait"
android:theme="@style/MyAppTheme"
android:windowSoftInputMode="stateHidden|adjustResize" />
<activity
android:name="Activity_C"
android:exported="false"
android:screenOrientation="sensorPortrait"
android:theme="@style/MyAppTheme"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="Activity_C" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
解决方案
发生这种情况是因为通常以前的活动保存在堆栈中,当用户按下后退按钮时,堆栈被调用,所以从我从你的问题中了解到,如果你想通过 Activity C 打开 Home Activity,只需通过覆盖将意图从 Activity C 调用到 Home Activity Activity C 中的 onbackpressed() 方法。这是一个示例。
Intent homeIntent = new Intent(this,HomeActivity);
startActivity(homeIntent);
finish();
finish() 用于移除堆叠的活动。
推荐阅读
- html - 如何在不使用媒体查询的情况下重新排列网格项目
- javascript - 访问模块脚本中定义的 html5 data-* 属性
- angular - 有没有办法手动打开 CKEditor 对话框?
- python - 从本地机器(外部)提交在 Docker 内运行的 Python 脚本时出现问题
- ocaml - 保持紧密的无分配循环可中断
- c# - 如何在 DataTrigger Setter 下使用由多个 TextBlock 组成的 WrapPanel
- java - 仅访问 JSON 数组中的第一个对象
- docker - NiFi Registry docker 文件未更新“远程克隆存储库”属性
- typescript - 将我的 SharePoint 框架扩展修改为仅在网站的主页上运行
- openedge - 如何在 Progress Developer Studio 中的现有 *.w 文件上打开可视化设计器?