简体   繁体   English

在android中注销后防止后退按钮

[英]Prevent back button after logout in android

After logout the user is directed to login screen in android.注销后,用户将被定向到 android 中的登录屏幕。 Now, if user clicks on back button of phone it should stay on login screen itself.现在,如果用户点击手机的后退按钮,它应该停留在登录屏幕本身。

How can I make it possible in android?我怎样才能在android中做到这一点?
I have used following code in my application but it will close my application.我在我的应用程序中使用了以下代码,但它会关闭我的应用程序。 It should stay on the login screen only它应该只停留在登录屏幕上

Intent objsignOut = new Intent(getBaseContext(),Hello.class);
objsignOut.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(objsignOut);

Please guide me the correct way.请指导我正确的方法。

After logout the user is directed to login screen in android.注销后,用户将被定向到android中的登录屏幕。 Now, if user clicks on back button of phone it should stay on login screen itself.现在,如果用户单击电话的后退按钮,则它应保留在登录屏幕本身上。

How can I make it possible in android?如何在android中实现呢?
I have used following code in my application but it will close my application.我在应用程序中使用了以下代码,但是它将关闭我的应用程序。 It should stay on the login screen only它应该只保留在登录屏幕上

Intent objsignOut = new Intent(getBaseContext(),Hello.class);
objsignOut.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(objsignOut);

Please guide me the correct way.请以正确的方式指导我。

After logout the user is directed to login screen in android.注销后,用户将被定向到android中的登录屏幕。 Now, if user clicks on back button of phone it should stay on login screen itself.现在,如果用户单击电话的后退按钮,则它应保留在登录屏幕本身上。

How can I make it possible in android?如何在android中实现呢?
I have used following code in my application but it will close my application.我在应用程序中使用了以下代码,但是它将关闭我的应用程序。 It should stay on the login screen only它应该只保留在登录屏幕上

Intent objsignOut = new Intent(getBaseContext(),Hello.class);
objsignOut.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(objsignOut);

Please guide me the correct way.请以正确的方式指导我。

After logout the user is directed to login screen in android.注销后,用户将被定向到android中的登录屏幕。 Now, if user clicks on back button of phone it should stay on login screen itself.现在,如果用户单击电话的后退按钮,则它应保留在登录屏幕本身上。

How can I make it possible in android?如何在android中实现呢?
I have used following code in my application but it will close my application.我在应用程序中使用了以下代码,但是它将关闭我的应用程序。 It should stay on the login screen only它应该只保留在登录屏幕上

Intent objsignOut = new Intent(getBaseContext(),Hello.class);
objsignOut.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(objsignOut);

Please guide me the correct way.请以正确的方式指导我。

After logout the user is directed to login screen in android.注销后,用户将被定向到android中的登录屏幕。 Now, if user clicks on back button of phone it should stay on login screen itself.现在,如果用户单击电话的后退按钮,则它应保留在登录屏幕本身上。

How can I make it possible in android?如何在android中实现呢?
I have used following code in my application but it will close my application.我在应用程序中使用了以下代码,但是它将关闭我的应用程序。 It should stay on the login screen only它应该只保留在登录屏幕上

Intent objsignOut = new Intent(getBaseContext(),Hello.class);
objsignOut.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(objsignOut);

Please guide me the correct way.请以正确的方式指导我。

The actual solution is实际的解决办法是

@Override
    public void onBackPressed() {
        super.onBackPressed();
        finishAffinity();
    }

add this code in Login Activity.在登录活动中添加此代码。 App closes when back button clicked in login page.在登录页面中单击后退按钮时,应用程序关闭。

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

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