Android中的多个权限对话框,方向更改后使用Google登录

Qua*_*eep 5 android google-login android-configchanges android-orientation

我已经和这个人争吵了一段时间 - 我在这里广泛搜索了答案,但没有发现任何答案(如果我错过了一个决议,那么道歉).我正在实施"使用Google登录"按钮/逻辑,除了更改设备方向外,所有工作都很正常.在这种情况下,我会看到Google的权限对话框的多个副本.(因此,如果我更改方向三次,则在返回到我的原始屏幕之前,我必须取消三个权限对话框的副本).(可以在此处找到权限对话框的示例).

我认为我的代码过于复杂,所以除了谷歌教程页面(入门/登录)中的代码外,我做了一个新的活动,我仍然遇到同样的问题.(以下代码)

(FWIW,我也尝试使用IntelliJ的"新建 - >活动 - >登录活动"选项创建一个新的活动,结果相同.)

除此之外,我尝试运行谷歌的"快速启动"应用程序,是的,同样的问题仍在发生!

有没有其他人成功实施"使用Google登录"而没有此行为?我认为作为最后的手段,我可​​以强制我的身份验证活动始终以纵向显示,但我正在尝试查看是否有超出此范围的解决方案.

先感谢您!

以下是我的"简化"活动的代码:

package com.myapp.test.view.housekeeping;

import android.content.Intent;
import android.content.IntentSender;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Toast;
import com.myapp.test.R;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.plus.Plus;

public class AuthenticateActivity_BareBones extends ActionBarActivity
        implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

    /* Request code used to invoke sign in user interactions. */
    private static final int RC_SIGN_IN = 1;

    /* Client used to interact with Google APIs. */
    private GoogleApiClient mGoogleApiClient;

    /* A flag indicating that a PendingIntent is in progress and prevents
     * us from starting further intents.
     */
    private boolean mIntentInProgress;

    /* Track whether the sign-in button has been clicked so that we know to resolve
     * all issues preventing sign-in without waiting.
     */
    private boolean mSignInClicked;

    /* Store the connection result from onConnectionFailed callbacks so that we can
     * resolve them when the user clicks sign-in.
     */
    private ConnectionResult mConnectionResult;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_authenticate);

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(Plus.API)
                .addScope(Plus.SCOPE_PLUS_LOGIN)
                .build();
    }

    @Override
    protected void onStart() {
        super.onStart();
        mGoogleApiClient.connect();
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (mGoogleApiClient.isConnected()) {
            mGoogleApiClient.disconnect();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case RC_SIGN_IN:
                if (resultCode != RESULT_OK) {
                    mSignInClicked = false;
                }

                mIntentInProgress = false;

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

    public void onButtonClick(View view) {
        int id = view.getId();
        switch (id) {
            case R.id.login_authenticate_google_button:
                if (!mGoogleApiClient.isConnecting()) {
                    mSignInClicked = true;
                    resolveSignInError();
                }
                break;
        }
    }

    @Override
    public void onConnected(Bundle connectionHint) {
        // We've resolved any connection errors.  mGoogleApiClient can be used to
        // access Google APIs on behalf of the user.
        mSignInClicked = false;
        Toast.makeText(this, "Connected to Google!", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onConnectionSuspended(int cause) {
        mGoogleApiClient.connect();
    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {
        if (!mIntentInProgress) {
            // Store the ConnectionResult so that we can use it later when the user clicks
            // 'sign-in'.
            mConnectionResult = result;

            if (mSignInClicked) {
                // The user has already clicked 'sign-in' so we attempt to resolve all
                // errors until the user is signed in, or they cancel.
                resolveSignInError();
            }
        }
    }

    /* A helper method to resolve the current ConnectionResult error. */
    private void resolveSignInError() {
        if (mConnectionResult.hasResolution()) {
            try {
                mIntentInProgress = true;
                startIntentSenderForResult(mConnectionResult.getResolution().getIntentSender(),
                        RC_SIGN_IN, null, 0, 0, 0);
            } catch (IntentSender.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();
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Ian*_*ber 0

mSignInClicked 实际上是在这段代码中为您保护旋转情况,因此分辨率被正确触发,仅一次。当“帐户选择器”对话框重新显示多次时,我得到了相同的行为。

这看起来像是 Google Play 服务版本 7 中的一个错误 - 将在上游归档此问题,希望在未来的版本中能够解决该问题。