Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GameHelper crashes on onConnectionFailed()

I've got the following crash in GameHelper.java:

[main] java.lang.NullPointerException at com.google.android.gms.common.ConnectionResult.startResolutionForResult(Unknown Source) at com.google.example.games.basegameutils.GameHelper.resolveConnectionResult(GameHelper.java:752) at com.google.example.games.basegameutils.GameHelper.onConnectionFailed(GameHelper.java:729)

The only reason I think that could happen is if mActivity == null at GameHelper.java:752:

mConnectionResult.startResolutionForResult(mActivity, RC_RESOLVE);

mActivity gets null on onStop() Is it possible that GameHelper.java has bug and can crash if onConnectionFailed() happens after onStop() is called? Thanks.

EDITED: It happened after update to the latest Play API (rev 15) together with the updated GameHelper.java.

like image 575
ivy_the Avatar asked Feb 25 '14 15:02

ivy_the


1 Answers

EDIT:

This now has been fixed in latest GameHelper version: https://github.com/playgameservices/android-samples/commit/e7b3758c136b5b434f1dfd9ca8c03f75aad70f09

OLD ANSWER:

For me it happens on the start of the app, when Google Play Services asks me to sign in and if I click cancel, this same error happens.

So when leaving from your own activity to sign in activity, it dispatches onStop event, and fails to connect because of the user initiated process, which is resolvable, thus the error happens.

So my quick hack was changing:

catch (SendIntentException e)

to simply

catch (Exception e)

So it would also catch Null pointer exception Of course in this case the signup process might not proceed, so I initate relogin on another action and it seems to work for now.

More thorough hack could be trying to resolve the result on activity start, for that we define pending resolution variable:

// Are we expecting the result of a resolution flow?
boolean mExpectingResolution = false;
boolean mPendingResolution = false;

Then on the error line we check if activity is not null

if(mActivity != null)
    mConnectionResult.startResolutionForResult(mActivity, RC_RESOLVE);
else
    mPendingResolution = true;

And on start we check and try to resolve it:

if(mPendingResolution && mConnectionResult != null)
try {
    mConnectionResult.startResolutionForResult(mActivity, RC_RESOLVE);
} catch (SendIntentException e) {
    e.printStackTrace();
}

This should help until the official resolution from lib supporters :)

like image 172
Artūrs Sosins Avatar answered Oct 23 '22 13:10

Artūrs Sosins