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.
billingClient.startConnection(this);
to retry. – GynaecocracystartConnection()
again fromonBillingServiceDisconnected()
a limited number of times. That shouldn't cause any issue and if it still crashes then leaveonBillingServiceDisconnected()
empty or just log the error. – GynaecocracyonBillingServiceDisconnected()
– Koren