【问题标题】:Google plus 'choose account' choose account does not disappears on cancel?Google plus“选择帐户”选择帐户在取消时不会消失吗?
【发布时间】:2015-02-12 04:58:21
【问题描述】:

我正在尝试使用 google plus 登录,它工作正常。我有多个帐户与我的帐户相关联,因此它显示弹出窗口以选择帐户,但是当我单击取消按钮时,它确实消失了。它一次又一次地出现。告诉我怎么做?

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
     if (requestCode == RC_SIGN_IN) 
     {
         Log.i("RAE","Result is  ");
            if (resultCode != RESULT_OK) {
              mSignInClicked = false;
            }

            mIntentInProgress = false;

            if (!mGoogleApiClient.isConnecting()) {
              mGoogleApiClient.connect();
            }
          }


}

连接失败

@Override
    public void onConnectionFailed(ConnectionResult result) {
        // TODO Auto-generated method stub
         if (!mIntentInProgress && result.hasResolution()) {
                try {
                  mIntentInProgress = true;
                  startIntentSenderForResult(result.getResolution().getIntentSender(),
                      RC_SIGN_IN, null, 0, 0, 0);
                } catch (SendIntentException e) {
                  // The intent was canceled before it was sent.  Return to the default
                  // state and attempt to connect to get an updated ConnectionResult.
                  mIntentInProgress = false;
                  mGoogleApiClient.connect();
                }
              }

    }

【问题讨论】:

  • 查看我更新的问题
  • 你也可以发布你的onConnectionFailed() 吗?
  • 请检查更新后的代码。 @ianhanniballake

标签: java android google-plus google-signin google-plus-signin


【解决方案1】:

您没有使用mSignInClicked 的值来确定是否使用startIntentSenderForResult() - 这意味着即使用户单击取消按钮,您仍然会一次又一次地调用startIntentSenderForResult() - 添加mSignInClicked到您的if 声明:

if (!mIntentInProgress && mSignInClicked && result.hasResolution()) {

如果您仍然希望在首次启动时获得类似自动登录的体验,您还应该在 onCreate() 中将 mSignInClicked 设置为 true,如果 savedInstanceState == null(即第一次启动活动时) )。这将确保每次用户启动活动时至少执行一次startIntentSenderForResult()。注意:您可能还想设置一个shared preference,说明您尝试了自动登录,如果您已经尝试自动登录并且他们取消了,则不要再次尝试自动登录。

【讨论】:

  • 我正在检查结果是否正常。
  • 如果条件写什么?
  • 这就是我回答的第二段的全部内容。
猜你喜欢
  • 2017-02-09
  • 2014-12-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-05
  • 2014-01-07
  • 1970-01-01
  • 2017-05-16
  • 1970-01-01
相关资源
最近更新 更多