I am implementing in-app-billing for the first time so I am a little confused about new purchases.
When you call launchBillingFlow() the Google Play UI purchase screen displays. If the purchase order is successful, the response data from Google Play is stored in a Purchase object that is passed back to the appropriate listener. Google Play then calls the onPurchasesUpdated() method to deliver the result of a purchase order to a listener that implements the PurchasesUpdatedListener interface.
And the signature of onPurchasesUpdated() method is like this:
void onPurchasesUpdated(@BillingResponse int responseCode, @Nullable List<Purchase> purchases);
My question: Does onPurchasesUpdated()
method deliver a list of ALL purchases initiated until now in my app or only latest initiated purchase?
If it delivers all purchases how do I find out latest initiated purchase?
As it's stated on the docs you provided, the method deliver a list of the latest Purchase
objects, either initiated on your app or on the Play Store.
(...) Both purchases initiated by your app and the ones initiated by Play Store will be reported here.
And if you look at the Purchase
class docs, you can see that there's a method called getPurchaseTime()
which you can use to check when that purchase was made. That's enough info to track which one was the latest purchase.
But you could also use the other methods on that class to keep track of the purchases, such as getOrderId()
.
But if you want to check all the purchases the user made on your app, and not only the most recent ones, take a look at the queryPurchases()
method, and take a look at the Query purchased items section on the training guide.