Explanation:
I've implemented the Google Sign In flow according to the official tutorial and only accounts that are already signed into the device are authenticated properly. When a user chooses "Use Another Account" or there are no Google accounts stored on the device once the user's credentials have been entered they are shown the login screen again but onActivityResult() is not triggered. Once I did get a GoogleSignInStatusCode 12502 which is SIGN_IN_CURRENTLY_IN_PROGRESS when I was returned to the login screen and tried to tap the Google sign in button again but most of the time it just authenticates normally at that point or doesn't do anything onClick.
Abbreviated Code:
case R.id.googleLoginButton:
googleSignIn();
break;
public void googleSignIn() {
mIsResolving = true;
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
this.startActivityForResult(signInIntent, RC_GOOGLE);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case RC_HINT:
// Drop into handling for RC_READ
case RC_READ:
if (resultCode == RESULT_OK) {
boolean isHint = (requestCode == RC_HINT);
Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);
processRetrievedCredential(credential, isHint);
} else if (resultCode == 1001){
//user chose a different account
} else {
Log.e(TAG, "Credential Read: " + resultCode);
Toast.makeText(this, "Credential Read Failed", Toast.LENGTH_LONG).show();
Crashlytics.log("Credential Read Failed");
}
mIsResolving = false;
break;
case RC_SAVE_PASSWORD_AUTH:
if (resultCode == RESULT_OK) {
return;
} else {
Log.e(TAG, "Credential Save: NOT OK");
Toast.makeText(this, "Credential Save Failed", Toast.LENGTH_LONG).show();
Crashlytics.log("Credential Save Failed");
}
mIsResolving = false;
break;
case RC_GOOGLE:
Log.d(TAG, "RC_GOOGLE");
Log.d(TAG, resultCode + "");
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
break;
default:
Log.d(TAG, "default case onActivityResult, requestCode " + requestCode + ", resultCode " + resultCode );
Crashlytics.log("default case onActivityResult, requestCode " + requestCode + ", resultCode " + resultCode );
break;
}
}
Troubleshooting I've Tried:
I had to change android:noHistory to false in my AndroidManifest.xml to allow the app to return to the login screen. Also tried startActivityForResult() with and without this. I've tried variations with setResult() instead of startActivityForResult, tried several Intent flags, checked my manifest for xml tags that might be obstructing onActivityResult(), checked SplashScreen, the only Activity in front of LoginSignupActivity, for code that might block onActivityResult(), added Log.ds which lead to the realization that onActivityResult was not being called in this case but worked in all other situations, tried with and without callbackManager, for Facebook auth, in onActivityResult(), and tried removing Smart Lock and various other pieces of code which had no effect.