如何销毁前一个activity,但移动到下一个activity时,splash和homeactivity不包括在内?

How to destroy the previous activity but splash and home activity is not included when moving to the next activity?

我有 6 个开放活动(见下图)。

但我想要发生的是,当用户继续 orderDetailsActivity 时,它将销毁所有先前的 activity,但不会销毁 splashActivityhomeActivity

因此用户可以轻松返回 homeActivity。请注意,我只想在返回 homeActivity 时使用 finish();

注意: 用户可以在 homeActivtycartActivitycheckoutActivity 之间来回移动,因此在移动到之后立即销毁这些活动另一个是不可能的。

你可以使用 finish()

在您的导航行中添加 finish()

 Intent it = new Intent (currentActivity.this,MovingActivity.class);
 startActivity(it);
 finish();

哪个activity不想破坏他们你只添加

 Intent it = new Intent (currentActivity.this,MovingActivity.class);
 startActivity(it);

当您从 Checkout Activity 移动到 Loading Activity 时,您可以简单地调用 finish() 来销毁 checkout activity

Loading Activity 的 onBackPressed 中你可以这样做:

Intent intent = new Intent (Loading.this , Home.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.ACITIVTIY_SINGLE_TOP);
startActivity(intent);  
finish();

这会将您重定向到 Home Activity(上一个实例)并将清除堆栈顶部的活动。所以,你想要的就实现了!

更多信息:Understand Tasks and Back Stack

更新:

如果您希望在 Order Details Activity 中发生同样的事情,您只需将代码放在 order detailsonBackPressed 中:

Intent intent = new Intent (OrderDetails.this , Home.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.ACITIVTIY_SINGLE_TOP);
startActivity(intent);  
finish();