Here is the method I've got:
public void setupBillingClient() { //connect to google play
billingClient = BillingClient.newBuilder(context)
.enablePendingPurchases()
.setListener(this)
.build();
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
//The BillingClient is setup successfully
loadAllSkus();
}
}
@Override
public void onBillingServiceDisconnected() {
//TODO: implement retry logic to handle lost connections to Google Play by calling startConnection() again
}
});
}
Google says I should "implement retry logic" but doesn't say how. I thought maybe to just call setupBillingClient()
inside onBillingServiceDisconnected()
but some people said that causes a crash. Also I feel if it was that simple then google would have told us to write that instead of the vague instruction to implement a retry logic.
I also ran into this issue. Google documentation about this is just a mess, (well, like the API itself).
So, here Google says
To implement retry logic, override the onBillingServiceDisconnected() callback method, and make sure that the BillingClient calls the startConnection() method to reconnect to Google Play before making further requests.
Which implies that after the disconnection we have to call startConnection
manually.
But here Google says
Called to notify that the connection to the billing service was lost.
Note: This does not remove the billing service connection itself - this binding to the service will remain active, and you will receive a call to onBillingSetupFinished(BillingResult) when the billing service is next running and setup is complete.
Which, in my opinion, absolutely contradicts the previous statement.
From my experience with the billing library, I believe the last statement is more likely to be true. I'm not 100% sure though.
But I can confirm that I saw a disconnect message in the logcat, followed by another message that the billing client was ready. I didn't do any restart actions though. Also, if I tried to startConnection
in disconnection callback, then I began to receive two messages in the logcat on each connection/disconnection.
Based on this, I can say that:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With