android - 不了解 Activity 堆栈?

标签 android

当它们进入后台时,我的 Activity 遇到了麻烦。我有两个 Activity ,A 和 B。只有 A 可以启动 B(下面复制的 list )。这就是我所做的:

  1. 从应用抽屉启动应用( Activity A)
  2. A 上有一个启动 B 的按钮,现在显示 B。
  3. 按下 Home 键,我的应用程序现在处于后台。
  4. 再次转到应用程序抽屉,点击我的应用程序图标。
  5. 不是在 ActivityB 恢复,而是再次启动 Activity A。为什么?
  6. 如果我现在按下返回键,我会看到旧的 ActivityB。什么?

这很令人困惑。这就像 Android 知道我的应用程序正在运行,并将 A 的新实例放在正在运行的旧 B 实例之上。我只是希望应用程序就地暂停,并且每当用户再次点击应用程序图标时,它就会从停止的地方开始(在这种情况下,只需再次显示 B!)下面是 list ,以及此测试的 Activity 类完全是空的(A 除外,它有一个启动 B 的按钮)。

<activity android:name=".ActivityA"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".ActivityB"
          android:label="@string/app_name">
        <intent-filter>
        <!-- 
            <action android:name="android.intent.action.VIEW" />
             -->
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

最佳答案

如果我不得不猜测,因为在你的应用程序抽屉里是你的程序 A 的 .apk 引用。无论 B 是否已经启动,应用程序的 INTENT 选择时都是启动程序A.

我只读了一点关于 Android 的资料,所以我不能 100% 肯定地说,但这是我的猜测。

希望对您有所帮助。

编辑:

在安卓手机上按住Home键,会出现后台应用列表,你能不能在模拟器里面做同样的事情,看看是否弹出程序B?还是出现同样的问题?

在阅读了有关 Google 的内容后,我遇到了 this这是一个小 fragment :

All the activities in a task move together as a unit. The entire task (the entire activity stack) can be brought to the foreground or sent to the background. Suppose, for instance, that the current task has four activities in its stack — three under the current activity. The user presses the HOME key, goes to the application launcher, and selects a new application (actually, a new task). The current task goes into the background and the root activity for the new task is displayed. Then, after a short period, the user goes back to the home screen and again selects the previous application (the previous task). That task, with all four activities in the stack, comes forward. When the user presses the BACK key, the screen does not display the activity the user just left (the root activity of the previous task). Rather, the activity on the top of the stack is removed and the previous activity in the same task is displayed.

我希望这能为您指明正确的方向

关于android - 不了解 Activity 堆栈?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1837512/

相关文章:

Android,如何混合使用 ActionBar.Tab + View Pager + ListFragment

android - 整合推特 : why can’t I post status without having to authenticate?

android - 使用 native 代码进入会导致 Android Studio 中出现垃圾

android - 是否可以在 Android 上访问扬声器信号?

java - 约束布局在不同设备上执行不同

Android 应用程序构建错误。无法合并 dex

android - 向 HexagonLoadingView 添加淡入淡出动画

Android 在变化时获取 WiFi 信号强度

android - 我应该把 zoomIn 放在我的 MapActivity 的什么地方?

android - 使用 Android 客户端的 Django 身份验证