Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3 onProductPurchase() called in another activity instead of the current one #503

Open
goman64 opened this issue Nov 8, 2021 · 5 comments

Comments

@goman64
Copy link

goman64 commented Nov 8, 2021

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.

@kcochibili
Copy link

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");

@svenoaks
Copy link

svenoaks commented Jul 7, 2022

@kcochibili pretty sure that singleton is leaking the activity on screen rotation and also the callbacks will stop working

@kcochibili
Copy link

@svenoaks can you specify where in the Singleton code you think could need improvement to prevent leaking?

@svenoaks
Copy link

svenoaks commented Jul 8, 2022

@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.

@Mohamedkivin
Copy link

Can you help me build in app billing 3 please؟

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants