ggenglish
ggenglish

Reputation: 1678

Android in-app billing cancel payment, application not active

I'm having trouble figuring out how the in-app billing process is supposed to work for broadcast events when the application isn't running. I have a managed product setup and as far as I can see, is working well. With a test account I'm able to purchase my published component and my test application handles it, retaining its state. I then cancel this order via my merchant account and the application again receives the event and removes the item.

The problem occurs when instead of cancelling the order while the application is active. I exit out of it (not with home, with multiple back buttons). If I cancel the item now, my 'device' gets a notification 'purchase failed', but when I start my application nothing seems to happen and thus the state of the item is still purchased.

I'm not sure if billing service is still running or not. Given the documentation says my application must send back a CONFIRM_NOTIFICATIONS or it keeps sending it I can only assume it is. However why is it unable to interact with my database and remove the item like it does correctly if the application is active?

I hope tihs is clear, and I apologize if it has been discussed before, I couldn't find anything in my searches.

Upvotes: 1

Views: 252

Answers (1)

ggenglish
ggenglish

Reputation: 1678

Apologies for answering my own question but hopefully my findings will help others that were confused as I was.

My issue was thinking that the Dungeons.java class provided in the example had all the code needed for modification. The example design has its database implementation nested in the observer class that is active while the user is interacting with the store. The issue it created for me outlined in my question, what happens if a transaction is cancelled after the fact when this observer isn't registered or the application isn't running.

From trial and error my solution was to take the database interaction out of the observer and place it in

private void purchaseStateChanged(int startId, String signedData, String signature) {

of the BillingService class.

Placed in here, when my broadcast receiver fires, I act on a cancellation and update my database accordingly regardless of whether my application is started much less my observer registered.

Upvotes: 1

Related Questions