【问题标题】:Googleapiclient is not disconnectingGoogleapiclient 没有断开连接
【发布时间】:2016-12-30 03:07:43
【问题描述】:

您好,我正在提供用于退出 Google 帐户的代码 sn-p。单击“注销”按钮时,我正在调用此注销功能。我能够成功使用谷歌帐户登录。使用下面的代码,我可以注销 Google 帐户,但需要多次单击注销按钮才能注销。我认为 mGoogleApiClient 连接的时间太长,因此进入 mGoogleApiClient.isConnected() 条件。

有人可以帮助我通过单击“退出”按钮退出 Google 帐户吗?

public void logout(String st)
{`enter code here`
   mGoogleApiClient.connect();
   if (mGoogleApiClient.isConnected()||mGoogleApiClient.isConnecting()) 
   {
        if(mGoogleApiClient.isConnected()) 
        {
            mGoogleApiClient.clearDefaultAccountAndReconnect();
            mGoogleApiClient.disconnect();
            System.err.println("LOG OUT ^^^^^^^^^^^^^^^^^^^^ SUCESS");
            refreshpage();
        }
    }
}

public void refreshpage()
{
    Intent intent = new Intent(this, SignInActivity.class);
    startActivity(intent);
}

【问题讨论】:

    标签: android google-api google-api-client google-signin googlesigninapi


    【解决方案1】:

    你为什么不这样使用

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

    【讨论】:

    • 还是一样...在点击 5 或 6 次后,它会断开连接:(
    • 答案已更新,通过使用它您可以显示一些(进度条)/(禁用按钮)
    • 对于上面的代码,当我尝试没有 if(mGoogleApiClient.isConnected()) 的 if 条件检查时,它会抛出 mGoogleApiClient is not yet connected 错误。但是当我再次添加支票时,它的行为是一样的。需要点击 5-6 次才能将其注销。我认为将 mGoogleApiClient 的状态从连接更改为已连接需要一些时间
    • 亲爱的它应该采用异步调用,但问题是你必须显示一些进度条或其他东西,直到你得到一些回调结果
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多