方向更改后使用谷歌登录的Android多权限对话框

方向更改后使用谷歌登录的Android多权限对话框,android,android-orientation,google-login,android-configchanges,Android,Android Orientation,Google Login,Android Configchanges,我已经为这个问题绞尽脑汁了一段时间——我在这里搜索了大量的答案,但没有找到任何答案(因此,如果我错过了一个解决方案,请道歉)。我正在实现一个“用谷歌登录”按钮/逻辑,除了改变设备方向外,其他一切都很好。在这种情况下,我会看到谷歌的“权限”对话框的多个副本。(因此,如果我更改方向三次,那么在返回到原始屏幕之前,我必须取消权限对话框的三个副本)。(可以找到“权限”对话框的示例) 我认为我把代码复杂化了,所以我做了一个新的活动,只使用了谷歌教程页面()中的代码,我仍然有同样的问题。(代码如下) (FW

我已经为这个问题绞尽脑汁了一段时间——我在这里搜索了大量的答案,但没有找到任何答案(因此,如果我错过了一个解决方案,请道歉)。我正在实现一个“用谷歌登录”按钮/逻辑,除了改变设备方向外,其他一切都很好。在这种情况下,我会看到谷歌的“权限”对话框的多个副本。(因此,如果我更改方向三次,那么在返回到原始屏幕之前,我必须取消权限对话框的三个副本)。(可以找到“权限”对话框的示例)

我认为我把代码复杂化了,所以我做了一个新的活动,只使用了谷歌教程页面()中的代码,我仍然有同样的问题。(代码如下)

(FWIW,我还尝试使用IntelliJ的“新建-->活动-->登录活动”选项创建新活动,结果相同。)

除此之外,我还试着运行谷歌的“快速入门”应用程序,是的,同样的问题还在发生

有没有其他人在没有这种行为的情况下成功实现了“使用谷歌登录”?我想,作为最后的手段,我可以强制我的身份验证活动总是出现在肖像中,但我正在尝试看看是否有一个解决方案超出这一点

提前谢谢你

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

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();
            }
        }
    }
}

在这段代码中,mSignInClicked实际上是在为您保护旋转情况,因此正确地触发了分辨率,仅触发一次。在多次重新显示Account Chooser对话框时,我也会得到相同的行为


这看起来像是Google Play Services第7版中的一个bug,它将在上游归档,希望在将来的版本中得到解决

这个问题仍然存在于新的GooglePlayServicesLib7.0.1中(使用示例应用程序可以轻松地重现)。除了您所写的内容之外,该问题还发生在“帐户选择器”对话框上@你有没有找到解决办法?