简体   繁体   English

如何在 android 中使用一个注销按钮实现 Facebook 和 Google 登录?

[英]How to implement Facebook and Google login with a one logout button in android?

你好朋友是 android、Facebook 和 google 的初学者以及使用单个注销按钮登录 android 应用程序

When the user logs in, you could store a variable, with a value of 'facebook' or 'google'.当用户登录时,您可以存储一个变量,其值为“facebook”或“google”。 When you click the log out button, check the value of the variable, then do whatever you need based on that.当您单击注销按钮时,检查变量的值,然后根据该值执行您需要的任何操作。

First intialize Facbook SDK with the below line of code on your user welcome activity.首先在您的用户欢迎活动中使用以下代码行初始化 Facbook SDK。

FacebookSdk.sdkInitialize(getApplicationContext());

Then, create a logoutUser() method that should be called on logout button click, like below;然后,创建一个 logoutUser() 方法,该方法应在单击注销按钮时调用,如下所示;

private void logoutUser() {
    LoginManager.getInstance().logOut(); // this is to logout Facebook

    Intent intent = new Intent(this, LoginActivity.class);
    intent.putExtra("finish", true); // if you are checking for this in your other Activities
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
            Intent.FLAG_ACTIVITY_CLEAR_TASK |
            Intent.FLAG_ACTIVITY_NEW_TASK |
            Intent.FLAG_ACTIVITY_NO_ANIMATION |
            Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    startActivity(intent);
    finish(); // This will kill all current logged in activities
}

Call this one method through one logout button onClickListner n thats it.通过一个注销按钮 onClickListner 调用这一方法,就是这样。

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

相关问题 如何使用Facebook登录在Android中实现注销功能 - How to implement logout functionality in android using facebook login Android:facebook登录和注销 - Android: facebook login & logout Android登录按钮中的Facebook登录集成在登录后更改为注销 - Facebook login intergration in android login button changes to logout after logged in 用于在Android中进行简单登录,Facebook,Google登录和注销的会话管理? - Session management for simple login, facebook , google login and logout in android? 如何在Android应用中使用Google,Facebook或Twitter实现用户登录? - How to implement user login with Google, Facebook or Twitter in Android app? 如何在Android中实现Facebook登录 - How to implement Facebook login in android 在Facebook Android SDK 4.0中设置按钮的登录/注销文本? - Set Login/Logout Text for Button in Facebook Android SDK 4.0? Android Firebase Facebook登录会在重新打开应用时显示“退出”按钮 - Android Firebase Facebook Login shows Logout button when app is reopened 如何在Android中使用Facebook sdk 4.7.0和自定义Google Plus登录按钮制作自定义Facebook登录按钮 - How to make a custom facebook login button using Facebook sdk 4.7.0 in android and a custom Google Plus login button Android Facebook:在一个活动中登录并在另一个活动中注销 - Android Facebook: Login in One activity and Logout in another activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM