如何在android中关闭应用程序

时间:2014-01-31 05:27:38

标签: android android-intent

您好我有两个活动1)登录页面2)它显示成功登录,我做得很完美但我的问题是我想在第二次活动关闭申请后再次打开新的登录页面请告诉我..

4 个答案:

答案 0 :(得分:1)

好吧,你可以这样做:
SecondActivity

中进行
@Override
public void onBackPressed() {
    Intent intent = new Intent(SecondActivity.this,FirstActivity.class);
    intent.setFlafs(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(i);
    finish();    //finish Second Activity
}

希望我回答你的问题。

答案 1 :(得分:0)

您可以在成功登录活动时调用finish方法。因此,当您再次回来时,您将看到登录页面活动。

答案 2 :(得分:0)

Intent activity= new Intent(FirstActivity.this,SecondActivity.class);

finish();            //This is used to close first activity

startActivity(activity);

答案 3 :(得分:0)

我将为您提供准确且有效的解决方案,这肯定会有效。

创建一个活动注销,然后编写此代码。

Intent intent = new Intent(Logout.this, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra("Exit me", true);
        startActivity(intent);
        finish(); 

MainActivity是您希望用户在注销后去的地方。

然后在每个活动中编写此代码。

if( getIntent().getBooleanExtra("Exit me", false)){
            finish();
            return; // add this to prevent from doing unnecessary stuffs
        }

这将完全退出您的Android应用程序,所有活动也将完成。