Android multiple permission dialogs using google login after changing orientation

I struggled with this for a while - and many times I searched for answers to them, but did not find it (so I apologize if I missed the resolution). I implement the "Log in to Google" button / logic and everything works fine EXCLUDES when it comes to changing the orientation of the device. In this case, I am provided with several copies of the Google rights dialog. (So ​​if I change the orientation three times, there are three copies of the dialog box with the permissions that I must cancel before returning to the original screen). (An example of a dialog with permissions can be found here ).

It seemed to me that I too complicated the code, so I did a new kind of activity using the code from Google tutorials ( Getting Started / Sign-In ), and I still have the same problem. (Code below)

(FWIW, I also tried to create a new action using the IntelliJ function "New → Activity → Login Activity" with the same results.)

In addition to this, I tried to launch the Google Quick Start application and yes, the same problem is still happening!

Has anyone else successfully implemented “Sign in to Google" WITHOUT this behavior? I suppose, as a last resort, I could make my authentication operation always appear in the portrait, but I'm trying to figure out if there is permission for this.

Thank you in advance!

Below is my code from my "simplified" operation:

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(); } } } } 
+5
source share
1 answer

mSignInClicked actually protects the rotation case for you in this code, so the resolution starts correctly only once. I get the same behavior when the account selection dialog is re-displayed multiple times.

This is similar to a bug in version 7 of Google Play Services - it will contain this file up, and I hope it should be taken care of in a future version.

0
source

Source: https://habr.com/ru/post/1207051/


All Articles