2
votes

I have the TrivialDrive app working but I still have a question on consumable purchases . . .

The app starts out in the onCreate event doing a queryInventoryAsync call to see what the inventory for this user is and, among other products, it checks to see if there is any gas in the google inventory. But it seems to me that there will never be any gas because whenever the user buys gas we "consume" it making a consumeAsync call.

It seems a gas inventory is never kept on the google servers and that the consumeAsync just accomplishes the billing of the consumable. (maybe it should be called billForConsumableAsync instead of consumeAsync?)

The TrivialDrive app is always keeping the consumable inventory in shared preferences memory.

If this is all true, so far then why does the app check for a gas inventory on the google server. There never will be any.

Also, if the user runs my app on another device, he won't see his gas inventory because it's being kept on the other device's memory.

So, my understanding is that with in-app billing, consumable inventory is never kept on the google servers - it must be managed by the app. That seems to be the wrong way to handle it.

2

2 Answers

0
votes

From a developers perspective, this does indeed seem like the wrong way to handle it. But it is quite attractive from Google's perspective, since it minimises the load on their servers.

0
votes

Consumable products (like for additional gas or virtual currency, etc.) are usually understood to only be credited towards one device. So, if you own a phone and a tablet and you buy more gas on the phone, you don't get more gas on the tablet. That's why the available gas (or virtual coin balance, or whatever) is stored only locally on the device rather than on a central server.

One of the reasons it is done this way is because it would be darn near impossible to make it work any other way (shared gas-tank for all devices) given that you can't rely on the fact that you have an internet connection at all times to update your server. So, if you fill your shared tank with 100 gallons of gas, you can then set your phone and your tablet to air-plane-mode and use up the full 100 gallons on both devices (since the tablet will never know that you've also been playing on the phone and vice versa). And next time your internet connections become available, you end up with -100 gallons of gas in your shared tank.

The reason why onCreate does a queryInventoryAsync-call is so that the app can catch and complete transactions where the purchase completed (i.e. The user got billed), but the app died before it had time to actually record the extra gas purchased.

But: I think that there are actually a couple of mistakes that Google made with the design of this purchase flow! You can read more about it in my related question on this issue. This question also might help explain in more detail why you need to do the queryInventoryAsync-call and what else to watch out for.