[英]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.