在 android 应用程序中从 google 和 facebook 注销 [英] Sign out from google and facebook in android application
问题描述
我已使用各自的方法集成了 google 和 facebook 注册.但是签名成功后,我想打开不同的活动,同样用户可以去各种不同的活动.我使用了操作栏,我在其中提供了从用户已登录的任一帐户注销的选项.当我处于不同的活动中时,我如何注销用户然后是主要活动.我遇到了一个异常,我无法将 apiclient 引用(对于 google)和会话引用(对于 facebook)传递给另一个活动.请帮忙.提前致谢.
I have integrated google and facebook sign up using their respective methods. But after successful signing, I want to open different activity and similarly user can go to various different activities. I have used action bar where I am giving an option to sign out from either of the account that the user has logged in. How could I sign out the user when I am in different activity then the main activity. I am getting an exception and I am not able to pass apiclient reference (for google) and session reference (for facebook) to another activity. Please help. Thanks in advance.
推荐答案
从谷歌退出:
只需将此添加到您的新活动中,您希望 google+ 的注销按钮出现在那里:
Just add this on your new activity, where you want your logout-button for google+ to be there :
@Override
protected void onStart() {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mGoogleApiClient.connect();
super.onStart();
}
接下来你可以在按钮上设置 setOnClickListener:
and next you can set setOnClickListener on button:
signout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
// ...
Toast.makeText(getApplicationContext(),"Logged Out",Toast.LENGTH_SHORT).show();
Intent i=new Intent(getApplicationContext(),MainActivity.class);
startActivity(i);
}
});
}
});
这篇关于在 android 应用程序中从 google 和 facebook 注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!