I am implementing In App Billing in my first app using trivial drive 2 example.
My simple implementation: the App is free and can be upgraded to a premium version via In App Billing providing some additonal features. These features are in different activities, sometimes an action can only be performed if premium is purchased, sometimes the activity looks different. So I only can have two different states: basic or premium.
I read a lot about this topic, but still have some questions about it. I guess many of the answers from stackoverflwo belong to an older implementation of in App Billing (like this one: How to best save InApp purchase status locally?).
Now my question: I have to check if user has premium status in different activities. What is the best practice doing it without always query purchases (performance)? Can it be checked once and used all over the app? Does anybody has some code examples of something similar? I thought this might be a common implementation, but didn't find anything...
By the way: the right method of checking if user purchased premium is queryPurchases from BillingClint - is that correct?
Thanks a lot for your help and thoughts!
Yes, you shouldn't query this all the time. You should do a check on the app startup and right after the user bought your in-app item.
You should have a singleton repository which you inject/pass into all your activities where it matters. The activities should ask this repository for the current state of purchase (ie: bought, not bought, unknown)
Probably you should implement a retry behaviour if it couldn't check online for whatever reason.
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