4

The scenario is:

launch app, start activity A, navigate to B, then to C press home button. C gets destroyed. Bring up task manager, press on my app's icon. Activity C is being recreated. How can I make this behaviour cease ? What I would like would be to go back to activity A.

The closest I could get to this was by launching activities B,C with Intent.FLAG_ACTIVITY_NO_HISTORY. But the problem with this flag is that it prevents activities B,C from ever being re-created throughout the app's life (they should be creatable once task manager leads user to A).

EDIT: same behaviour observed as in Intent.FLAG_ACTIVITY_NO_HISTORY case if I use this approach instead:

class C extends Activity
{
...
    @Override
    protected void onDestroy() 
    {
        // last resort
        finish();
        super.onDestroy();      
                //finish();
    }
}

I can not navigate back to activity C once it its onDestroy() has been called once :(

Thanks

4

2 回答 2

0

编辑您的 Manifest.xml 文件并在您不想重新创建的活动中指定:

android:launchMode="singleTask"

或根据您的要求使用其他属性。去这里 详细解释。

于 2013-08-18T18:56:16.743 回答
0

经过一个周末的人机大战,这就是我所经历的:

noHistory ="true" 活动属性阻止它们从活动堆栈中位于它们下方的另一个活动启动 (startActivity())。事情是整个活动导航逻辑通过一个方法传递这个标志添加到意图:

context.startActivity(intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));

Android 无法“重新排序”“noHistory”活动,我认为这是一个错误。由于 noHistory 活动已经完成(),它应该召唤一个新的实例......有效的是在活动 A 上使用 FLAG_ACTIVITY_CLEAR_TOP(参见 OP)。这样,B 和 C 在所有场景中都得到了正确的实例化。然而,这还不够,我最终完成()所有活动,因为我一方面因为 OOM 错误而离开它们,另一方面是生命周期/应用程序逻辑的复杂性。

于 2012-09-24T04:54:27.083 回答