Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR tries to solve issues brought up in #315 , specifically that methods are invoked on
mBillingClient
when it isnull
. See my comment there for a discussion of the problem. Copy-pasted here, the variableclientReady
is being used to track if the billing client setup has been completed, by setting it tofalse
in the onBillingServiceDisconnected() callback. ButmBillingClient
itself is set tonull
immediately whenendConnection()
is called. This is a mismatch. It's possible forclientReady
to remain set totrue
, even ifmBillingClient
isnull
. In that case, methods will be invoked by the on the null object instance. It seems that something is preventingonBillingServiceDisconnected()
from being called.Solution:
avoid setting
mBillingClient
tonull
. It is still not initialized in the class constructor, so will benull
beforeensureConnection()
is called for the first time. Thus the null checks are still necessary.Remove the
clientReady
property in favor of relying onmBillingClient.isReady()
(again checking for null before calling).The root cause of this issue is that when
endConnection()
is called as a React Native component is unmounting, it seems that theonBillingServiceDisconnected()
callback is never invoked. I don't know whether this is intended by the API or not, so I did not attempt to change this. I suggest someone with more experience in Android In App Billing review this PR before it is merged.