简体   繁体   English

如何在Android中设置后台堆栈中的活动限制?

[英]How to set the limit of activities in back stack in Android?

In the app that I am making, there are 12 different activities linked to the main page. 在我正在制作的应用程序中,有12个不同的活动链接到主页面。 All of them are independent of each other. 所有这些都是相互独立的。 I want the previous activities removed from the back stack so that the app takes less memory. 我希望从后台堆栈中删除以前的活动,以便应用程序占用更少的内存。 I have managed to have single instance of each activity by using 我已经设法使用了每个活动的单个实例

android:launchMode = "singleInstance"

But still when these activities are started from the main page, 12 different pages go in the back stack and app crashes. 但是当这些活动从主页面开始时,12个不同的页面进入后台堆栈并且应用程序崩溃。 What is the work-around? 什么是解决方法?

It sounds like android:noHistory="true" would be the solution for you. 听起来像android:noHistory =“true”将是你的解决方案。

A value of "true" means that the activity will not leave a historical trace. 值“true”表示活动不会留下历史痕迹。 It will not remain in the activity stack for the task, so the user will not be able to return to it. 它不会保留在任务的活动堆栈中,因此用户将无法返回该任务。

How does android:noHistory="true" work? android:noHistory =“true”是如何工作的?

when you go back start the MainActivty,call this on backpress on 12 activitys. 当你回去开始MainActivty时,在12个活动的背压上调用它。

Intent intent  = new Intent(youeActivity.this,MainActivity.class); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);      
startActivity(intent);
finish();

manofest add this one manofest加上这一个

android:excludeFromRecents="true"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM