GameHelper crashes on onConnectionFailed()

前端 未结 2 329
清酒与你
清酒与你 2021-01-12 04:09

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

[main] java.lang.NullPointerException at com.google.android.gms.common.Connection

2条回答
  •  时光说笑
    2021-01-12 04:33

    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 :)

提交回复
热议问题