Open goman64 opened 3 years ago
Hello, I had the same issue, to fix it , I created this singleton class that automatically holds a reference to the BillingProcessor instance. it should fix your issue, check it out.
Here is an example usage below:
Example 1:
put this in the onResume
method of every activity that uses billing:
@Override
protected void onResume() {
super.onResume();
BillingHolder.getInstance().getBp(this); // must be in every activity that uses billing
}
to use this class, simply use it directly like below.
BillingHolder.getInstance().getBp(this).purchase(this, "food");
Example 2:
put this on the onResume
method of every activity that uses billing:
public BillingProcessor bp;
@Override
protected void onResume() {
super.onResume();
bp = BillingHolder.getInstance().getBp(this); // must be in every activity that uses billing
}
usage:
bp.purchase(this, "food");
@kcochibili pretty sure that singleton is leaking the activity on screen rotation and also the callbacks will stop working
@svenoaks can you specify where in the Singleton code you think could need improvement to prevent leaking?
@kcochibili I think calling killLast()
in onDestroy()
of every Activity would prevent it. You did make that public so it's fine, but not mentioned in the gist.
Can you help me build in app billing 3 please؟
I have updated to 2.0.0.
I have two instances of BillingProcessor in 2 activities: FirstActivity and SecondActivity. Both activities allow different in-app purchases. However, when FirstActivity calls SecondActivity and a purchase is made on the latter, the onProductPurchase() of FirstActivity is being called. I did not have this issue earlier. Kindly advise.