question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

You have forgot to add the BillingClient.endConnection() to the PurchaseManagerGoogleBilling.dispose() method

See original GitHub issue

https://github.com/libgdx/gdx-pay/blob/1dade184a96dae53a758988482f4d7397b27249a/gdx-pay-android-googlebilling/src/com/badlogic/gdx/pay/android/googlebilling/PurchaseManagerGoogleBilling.java#L170-L178

In javadocs of BillingClient.java it says:

When you are done with this object, don’t forget to call endConnection() to ensure proper cleanup. This object holds a binding to the in-app billing service and the manager to handle broadcast events, which will leak unless you dispose it correctly. If you created the object inside the onCreate(Bundle) method, then the recommended place to dispose is the the onDestroy() method.

BillingClient.java

The TrivialDrive v2 sample app shows this has endConnection() too:

public void destroy() {
        Log.d(TAG, "Destroying the manager.");

        if (mBillingClient != null && mBillingClient.isReady()) {
            mBillingClient.endConnection();
            mBillingClient = null;
        }
    }

TrivialDrive v2 sample app BillingManager.java

I use PurchaseManager.dispose() on the Game.dispose()

In this case all good: start app-> start purchase-> cancel purchase-> home button-> start app-> start purchase-> cancel purchase

But I see crashes in this case: start app-> start purchase-> cancel purchase-> back button (this causes Gdx.app.exit() in my case and PurchaseManager.dispose()) -> start app-> start purchase-> cancel purchase-> -> CRASH REPORT

 com.prozhar.ua.spelling E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.prozhar.ua.spelling, PID: 24311
    java.lang.NullPointerException: Attempt to invoke interface method 'void com.badlogic.gdx.pay.PurchaseObserver.handlePurchaseCanceled()' on a null object reference
        at com.badlogic.gdx.pay.android.googlebilling.PurchaseManagerGoogleBilling.onPurchasesUpdated(PurchaseManagerGoogleBilling.java:211)
        at com.android.billingclient.api.BillingClientImpl$1.onReceive(BillingClientImpl.java:136)
        at com.android.billingclient.api.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:303)
        at com.android.billingclient.api.LocalBroadcastManager.access$000(LocalBroadcastManager.java:44)
        at com.android.billingclient.api.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:114)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6944)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Sorry for my english. Fix it faster plaese I use your perfect library in production. 😃

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
MrStahlfelgecommented, Sep 22, 2018

I see. It will be fixed with the two steps mentioned. I’ll add the null checks and call to endConnection next week.

0reactions
MrStahlfelgecommented, Oct 15, 2018

This issue can be closed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

When to call BillingClient.endConnection()? - android
If you created the object inside the onCreate(Bundle) method, then the recommended place to dispose is the onDestroy() method. In my App, it ......
Read more >
BillingClient
This object holds a binding to the in-app billing service and the manager to handle broadcast events, which will leak unless you dispose...
Read more >
BillingClient.endConnection - Java
How to use. endConnection. method. in. com.android.billingclient.api.BillingClient ... PurchaseManagerGoogleBilling.dispose().
Read more >
In-app Purchasing with Google Play Billing Library
If you created the object inside the onCreate(Bundle) method, then the recommended place to dispose is the onDestroy() method.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found