android - 顶级 Android Activity

标签 android android-intent

我正在尝试使用 AppCompat Drawer 和多个顶级 Activity (不是 fragment )创建一个基本应用程序 - 我不太清楚如何管理后台堆栈 - 我已经尝试了大约一百种不同的方法- 但它们都需要某种奇怪的 hack 来清除后台堆栈 - 或完成现有 Activity 。

我有 3 个 Activity - A、B 和 C。A 和 B 是顶级的,C 是 B 的 child

我要:

  • 在应用启动时启动 Activity A
  • 当我按下 A 的后退按钮时退出应用
  • 从抽屉中启动 Activity B
  • 当我从 B 按下后退按钮时退出应用
  • 从 Activity B 启动 Activity C
  • 当我从 C 按下后退按钮时返回到 Activity B
  • 当我通过选择抽屉按钮从 B 启动 B 或从 A 启动 A 或从 C 启动 B 时 - 我应该让顶级 Activity 恢复到原始状态。

我有:

protected void startActivity(Class activity) {
    final Intent intent = new Intent(this, activity);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    startActivity(intent);
    overridePendingTransition(0, 0);
}

基本上,我传入 ActivityA.class 或 ActivityB.class - 使用这种方法 - 从 B 返回将我带到 A

使用 HO_HISTORY,看起来不错 - 但从 C 键返回退出应用程序

使用 REORDER_TO_FRONT 似乎没有做任何事情??

在 startActivity 之后使用 finish() 效果很好——除非你选择 A 或 B 两次(在这种情况下你退出应用程序)

使用 FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK 以各种方式完美工作 - 除了在重新创建任务时 super 讨厌的屏幕闪烁。并且性能达到...

帮助??

最佳答案

您不能在调用 starActivity 之后立即调用 finish() 吗? (您也必须删除 SINGLE_TOP 标志 - 否则您会遇到从 B -> B 时提到的行为)

关于android - 顶级 Android Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19286787/

相关文章:

java - 当有 if 语句时自定义 ListView 滞后

android - 当前 Activity 未收到搜索 Intent

java - 是否可以将图像传输到 3 个不同的 Activity ?

java - 安卓 5.0 IllegalArgumentException : Service Intent must be explicit: on com. google.android.location.internal.GoogleLocationManagerService.START

android - ActivityNotFoundException : No Activity found to handle Intent { act=android.intent.action.VIEW dat=文件:///mnt/sdcard/testdata5.pdf

java - 使用 TestFairy 获取 Travis-CI 构建的视频记录

android - 如何修复渲染缓慢 (Android vitals)

android - WebView 客户端的 onReceivedHttpError 和 onReceivedError b/w 有什么区别

java - 单击两次按钮显示不同的当前时间并在每次单击时刷新

android - 无法使用 Intents 在 Android Lollipop 5.0 中进行视频通话