如何管理活动栈?

2023-09-12 05:03:12 作者:血腥玛丽

在我的筹码是在这种情况下:

When my stack is in this situation:

A->B->C

如果我开始开发活动,我想该活动栈变成:

if I start D activity, I want that the activity stack becomes:

A->D

请注意该活动C是一个对话框。

Note that activity C is a dialog.

推荐答案

下面是它会做的步骤所需要的:

here are the steps which will do the needed:

从活动Ç推出的活动时,用布尔 fromActivityC 捆绑的意向和标志 FLAG_ACTIVITY_CLEAR_TOP 设置。

现在,在活动的上创建检查这个布尔fromActivityC第一,如果present启动活动Ð其他正常的流程继续。 from activity C launch the activity A with a boolean fromActivityC bundled with the intent and the flag FLAG_ACTIVITY_CLEAR_TOP set .

Now in the on create of the activity A check for this boolean "fromActivityC" first and if present launch the activity D else the normal flow continues.

// following code can be used to get the boolean in the oncreate
boolean entrypoint=this.getIntent().getExtras().getBoolean("fromActivityC");

有一个可爱的小的解决方法,但希望它可以帮助

A lil workaround but Hope it helps

相关推荐