0
所以,我有这个程序有4个不同的活动:我应该如何使用Back Stack来允许使用后退按钮?
- A是三个按钮的主要活动,推出B,C和d(我认为,人们用它来指代这些作为子活动)。
- 每个活动都有自己的布局,但我认为这不是相关 在这里。
我想要做的是大多数应用程序的标准行为。那就是:
- 我开始通过启动应用程序,看到活动A.
- 然后我按下一个按钮,C,例如,并且显示出活性℃。
- 然后我按下后退按钮,活动A再次显示。
我的应用程序正确地指出了第1和第2点,但是第3位的应用程序消失了。按钮的
的onclick方法是这样的:
startActivity(new Intent(this,C.class));
活动没有覆盖onBackPressed方法。
这里是(部分)我的清单文件:从调试工作
<activity android:name=".A" android:label="A" android:launchMode="standard" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".B" android:label="B" android:launchMode="standard" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"/>
<activity android:name=".C" android:label="C" android:launchMode="standard" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"/>
<activity android:name=".D" android:label="D" android:launchMode="standard" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"/>
我知道我所做的,是A.onDestroy()按钮的onclick方法被调用后调用。 基于这些信息,我认为,当然我可能是错的,出于某种原因,操作系统从操作系统中删除了活动A.
现在我知道这种问题已经在这里解决stackoverflow,但我已经尝试了所有的建议,我可以找到和没有工作。 我想解释我自己的情况。
如果调用A.onDestroy(),则无法将A取回到活动堆栈中(手动调用A,但它不会位于堆栈中的正确位置)。你在onPause()中做什么?你覆盖了吗? – stefan 2012-02-28 16:20:22
A活动应该在堆栈中。当你开始新的活动时,你使用finish()吗?我使用了很多,唯一的做法是在清单中设置noHistory属性。我从来没有使用android:launchMode =“standard”,但它看起来并不像这样关闭了活动 – colegu 2012-02-28 16:26:51
@stefan我不重写onPause。我重写onResume(这是我膨胀布局)。我通过做你所说的工作,手动调用A,但它不是优雅的地方...... – 2012-02-28 16:31:56