• 4
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

  • Google Play Services Version 11.6.2
  • Target Android SDK 27

I have implemented the suggested new GoogleSignIn flow by referencing TypeANumber project provided by Google in the repository below :

https://github.com/playgameservices/android-basic-samples/blob/master/TypeANumber/src/main/java/com/google/example/games/tanc/MainActivity.java

Crash scenario :

  • User authenticated and signed in successfully.
  • App pauses and resumes.
  • User tries to sign out from Google by calling the signout method below.

This is my initialize code :

public void initialize(Activity activity, View viewForGamePopups) {
    this.activity = activity;
    this.viewForGamePopups = viewForGamePopups;
    GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).
            requestServerAuthCode(backendClientId).
            requestProfile().
            build();
    googleSignInClient = GoogleSignIn.getClient(activity, googleSignInOptions);
}

For sign in :

public void signIn() {
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if(isSignedIn()) {
                silentSignIn();
            } else {
                activity.startActivityForResult(googleSignInClient.getSignInIntent(), RC_SIGN_IN);
            }
        }
    });
}

public boolean isSignedIn() {
    return GoogleSignIn.getLastSignedInAccount(activity) != null;
}

public void onActivityResult(int requestCode, int responseCode, Intent intent) {
    if (requestCode == RC_SIGN_IN) {
        try {
            Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(intent);
            GoogleSignInAccount account = task.getResult(ApiException.class);
            setViewForGamePopups(account);
            onConnected(account);
        } catch (ApiException apiException) {
            String message = apiException.getMessage();
            if (message == null || message.isEmpty()) {
                message = "Unexpected error!";
            }
            onDisconnected();
        }
    }
}

private void silentSignIn() {
    googleSignInClient.silentSignIn().addOnCompleteListener(activity,
        new OnCompleteListener<GoogleSignInAccount>() {
            @Override
            public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
                if (task.isSuccessful()) {
                    GoogleSignInAccount googleSignInAccount = task.getResult();
                    setViewForGamePopups(googleSignInAccount);
                } else {
                    signOut();
                }
            }
        }
    );
}

For sing out :

public void signOut() {
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (!isSignedIn()) {
                return;
            }
            googleSignInClient.signOut().addOnCompleteListener(activity,
                new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        ...
                    }
                }
            );
        }
    });
}

Crash occurs with the following stack trace :

Fatal Exception: java.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called. at com.google.android.gms.common.internal.zzd.zzaka(Unknown Source:10) at com.google.android.gms.common.internal.zzd.zzakb(Unknown Source:17) at com.google.android.gms.games.internal.GamesClientImpl.zzg(Unknown Source:5) at com.google.android.gms.games.internal.GamesClientImpl.zza(Unknown Source:5) at com.google.android.gms.common.api.internal.zzbr.signOut(Unknown Source:77) at com.google.android.gms.common.api.internal.zzbp.zzaih(Unknown Source:26) at com.google.android.gms.common.api.internal.zzbp.handleMessage(Unknown Source:507) at android.os.Handler.dispatchMessage(Handler.java:101) at android.os.Looper.loop(Looper.java:164) at android.os.HandlerThread.run(HandlerThread.java:65)

I have added silent sign in for onResume case as suggested in the TypeANumber sample.

public void onResume() {
    logD("Silent sign in onResume called!");
    googleSignInClient.silentSignIn().addOnCompleteListener(new OnCompleteListener<GoogleSignInAccount>() {
        @Override
        public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
            if(task.isComplete()) {
                logD("Google Connection completed!");
            }
            if(task.isSuccessful()) {
                logD("Google Connection success!");
            } else {
                logD("Google Connection failed!");
            }
        }
    });
    logD("Silent sign in onResume ended!");
}

Even if I press sign out button after silent sign in has been completed (onResume), I am still getting this crash.

Is there any workaround for this problem?

As I said in the post, calling silentSignIn in "onResume" callback of the activity didn't help to fix the crash with the Google Play Service Version 11.6.2. After upgrading the Google Play Service Version to 12.0.1, I couldn't reproduce the crash again. Even after removing silentSignIn call in "onResume" method, the app didn't crash anymore.

  • 1
Reply Report