[英]How to destroy the previous activity but splash and home activity is not included when moving to the next activity?
I have 6 open activities (see the image below).我有 6 个开放的活动(见下图)。
But what I want to happen is when the user proceeds to orderDetailsActivity
it will destroy all the previous activity but not the splashActivity
and homeActivity
.但我希望发生的是当用户进入orderDetailsActivity
它会破坏所有以前的活动,但不是splashActivity
和homeActivity
。
So the user can easily move back to homeActivity
.所以用户可以很容易地回到homeActivity
。 And please note that I want to use finish();
请注意,我想使用finish();
when moving back to homeActivity
only.仅当搬回homeActivity
。
Note: The user can move back and forth from homeActivty
, cartActivity
and checkoutActivity
so destroying those activities right after moving to another one is not possible.注:用户可以来回移动,从homeActivty
, cartActivity
和checkoutActivity
移动到另一个之后所以破坏这些活动是不可能的。
When you move from Checkout Activity
to Loading Activity
you can simply call finish() to destroy the checkout activity
.当您从Checkout Activity
移动到Loading Activity
您可以简单地调用 finish() 来销毁checkout activity
。
In the onBackPressed of Loading Activity
you can do like:在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();
This would redirect you to the Home Activity
(previous instance) and will clear the activities which are on top of the stack.这会将您重定向到Home Activity
(前一个实例),并将清除堆栈顶部的Home Activity
。 Therefore, what you want is achieved!所以,你想要的就实现了!
For more info: Understand Tasks and Back Stack有关更多信息: 了解任务和返回堆栈
If you want the same thing to happen in the Order Details Activity
, you just put the code in onBackPressed
of order details
:如果您希望在Order Details Activity
发生同样的事情,您只需将代码放在order details
onBackPressed
中:
Intent intent = new Intent (OrderDetails.this , Home.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.ACITIVTIY_SINGLE_TOP);
startActivity(intent);
finish();
You can use finish()您可以使用完成()
In your navigation line you add finish()在您的导航行中添加完成()
Intent it = new Intent (currentActivity.this,MovingActivity.class);
startActivity(it);
finish();
and which activity not want to destroy their you add only以及哪些活动不想破坏您只添加的活动
Intent it = new Intent (currentActivity.this,MovingActivity.class);
startActivity(it);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.