清空行业堆栈,并开始在android的新活动 [英] Clear Activity Stack and start new activity in android

查看:128
本文介绍了清空行业堆栈,并开始在android的新活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是比这些类型的问题略有不同。我需要删除或清除我的活动堆栈然后启动一个新的活动。我不认为这是一个clear_top标志问题。我解释一个例子:

My question is little bit different than these type of question. I need to remove or clear my activity stack then start a new activity. I don't think it is a clear_top flag problem. I am explaining with an example:

我的活动流程:

Login > Home > Screen1 > screen2 ....

我完成登录活动或no_history标志调用。因此,我的活动看起来像这样

I finish Login activity or call with no_history flag. So my activities are look like this

Login(finished)> Home [bottom of the stack now] > Screen1 > Screen2[top of the stack]

我需要处理会话错误。如果在任何时候发生任何会话错误,我需要回去登录活动。但是,请记住我没有登录活动的堆栈。所以clear_top将无法正常工作。

I need to handle session error. If any session error occurs in any point i need to go back to login activity. But remember i don't have login activity in stack. So clear_top will not work.

如果在画面2发生任何会话错误,那么我需要清晰的全栈(屏幕2,屏幕截图,家庭),然后开始登录活动。因此,经过后退按钮preSS在登录活动将关闭我的应用程序。

If any session error occurs in Screen2 then i need to clear full stack (screen2, screen1, home) and then start login activity. So that after back button press in login activity will close my apps.

有没有什么办法来清除活性栈?

Is there any way to clear the activity stack?

在此先感谢

推荐答案

使用该

Intent i = new Intent(yourScreen.this,Home.class);
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        i.putExtra("EXIT", true);
        startActivity(i);

和在家庭类的OnCreate,这样做是为了检查,

and in the onCreate of the Home class, do this to check,

if (getIntent().getBooleanExtra("EXIT", false)) 
    {
        Intent i = new Intent(Home.this,Login.class);
        startActivity(i);
        finish();
    }

这是什么将主要做的是,无论你是什么样的活动,你可以调用带有明显的顶部标志的主屏幕。在主屏幕中有一个在onCreate方法检查条件,这将有助于清除栈,并带您到登录屏幕。现在登录屏幕上,如果你preSS后退按钮,您将退出该应用程序为堆栈被清除。

what this will essentially do is no matter at what activity you are, you can call the home screen with the clear top flag. In the home screen there is a check condition in the onCreate method which will help to clear the stack and take you to the login screen.. Now on the login screen,if you press back button you will exit the app as the stack is cleared..

让我知道如果问题仍然存在...

Let me know if the problem still persists...

这篇关于清空行业堆栈,并开始在android的新活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆