当它们进入后台时,我的 Activity 遇到了麻烦。我有两个 Activity ,A 和 B。只有 A 可以启动 B(下面复制的 list )。这就是我所做的:
- 从应用抽屉启动应用( Activity A)
- A 上有一个启动 B 的按钮,现在显示 B。
- 按下 Home 键,我的应用程序现在处于后台。
- 再次转到应用程序抽屉,点击我的应用程序图标。
- 不是在 ActivityB 恢复,而是再次启动 Activity A。为什么?
- 如果我现在按下返回键,我会看到旧的 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/