【问题标题】:Facebook logout issue in another activity另一个活动中的 Facebook 注销问题
【发布时间】:2016-02-24 09:13:06
【问题描述】:

我正在我的 android 应用程序中实现 google+ 和 facebook 集成。通过 facebook 或 google+ 登录后,下一个活动将到来。在该活动中,我如何使用我的注销按钮管理 facebook 和 google+ 注销?

public void googlePlusLogout() {
if (LoginActivity.mGoogleApiClient.isConnected()) {
Plus.AccountApi.clearDefaultAccount(LoginActivity.mGoogleApiClient);
LoginActivity.mGoogleApiClient.disconnect();
   }
} // Update - coed formatting

public void facebookLogout(){
LoginManager.getInstance().logOut();
}

facebooklogout 方法运行良好。但是,如果我调用 google+ 注销方法,它就不起作用了。

【问题讨论】:

  • 你想要两个单独的注销吗??
  • 是的。实际上我有 3 个单独的注销。我必须管理所有三个注销,即 facebook、google+ 和我的应用登录,应该在一个注销按钮中实现。

标签: android facebook google-plus


【解决方案1】:

调用此函数以退出 Google Plus

 private void googlePlusLogout() {
        if (mGoogleApiClient != null)
            if (mGoogleApiClient.isConnected()) {
                Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
                mGoogleApiClient.disconnect();
                mGoogleApiClient.connect();
            }
    }

【讨论】:

  • 获取 mGoogleApiClient 为空
  • 在登录活动中,我为 GoogleApiClient mGoogleApiClient 保留了公共静态;通过使用类名,我得到 mGoogleApiClient
  • 如果我删除静态,我如何在另一个活动中访问它?
  • 我正在使用这个链接androidhive.info/2014/02/…
  • 非常感谢您的帮助。现在我正在注销。我再次在我的另一个活动中添加了此代码 mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this).addApi(Plus.API) .addScope(Plus.SCOPE_PLUS_LOGIN).build();跨度>
【解决方案2】:

试试这个:

 public void  signoutGoogle(){

            Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
                   new ResultCallback<Status>() {
                       @Override
                       public void onResult(Status status) {

                           Intent intent = new Intent(HomeActivity.this, HomeActivity.class);
                           startActivity(intent);


                       }
                   });
       }

【讨论】:

    猜你喜欢
    • 2015-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多