Purchase marked as Restored is crashing the app

In my testing of the Amazon Appstore in my app, I am running into a crash situation on a very specific act.

If I purchase an entitlement in my app, then go and remove and reinstall the app (or clear the cache to make the app forget that it was purchased), then go and try to purchase again, I get the message that the item has already been purchased as expected.

If I click the Close button in the Amazon window (which I hear click), the window doesn’t close and a few seconds later, the app crashes.  I get an Android screen:

Sorry!

The application NAME (process [package name]) has stopped unexpectedly.  Please try again.

|Force close|

If I am able to click the Close button a second time before the app crashes, the window does close.  The app still crashes, however.

Is this a problem with the AmazonSDKTester functionality?  Or is this something that happens using the actual production workflow as well?  I would think not, but not sure what is happening.

Hi thegdog,

You should not be getting any crashes due to the Amazon SDK Tester.

Do you have the logcat messages that happened when this crash occurred? It is very difficult to know what happened without this information.

Look here if you are unsure how to collect this data.

-Preston

Nope, it wasn’t the Amazon SDK Tester.

I didn’t think that my code for the restored state had started running yet, that it required the Amazon window to close first.  But that is not the case.  So it was entering the callback and trying to access the event data to unlock that purchase, but in this case, none of that event data is present.  So I think that is what was causing the crash.

I’ve worked around it in two different ways, one of them being doing a store.restore() on app load.

My only concern with this is that the way that I had the store functionality coded, it was not global.  It was contained in a function, with the callback a local function inside of that.  Which means that I couldn’t use that callback outside of it.  So now I am doing a store.init() on load with its own callback (that only handles restored/revoked states), then doing another store.init() once the user gets into the “store” area of the app, that handles all the states.

It appears to be working.  Is there any problem with doing that?

While the plugin was not designed for you to call init() multiple times, I do not see any issue in doing so. If it is working during your testing than it should be fine.

Thanks again for the help, Preston.

Hi thegdog,

You should not be getting any crashes due to the Amazon SDK Tester.

Do you have the logcat messages that happened when this crash occurred? It is very difficult to know what happened without this information.

Look here if you are unsure how to collect this data.

-Preston

Nope, it wasn’t the Amazon SDK Tester.

I didn’t think that my code for the restored state had started running yet, that it required the Amazon window to close first.  But that is not the case.  So it was entering the callback and trying to access the event data to unlock that purchase, but in this case, none of that event data is present.  So I think that is what was causing the crash.

I’ve worked around it in two different ways, one of them being doing a store.restore() on app load.

My only concern with this is that the way that I had the store functionality coded, it was not global.  It was contained in a function, with the callback a local function inside of that.  Which means that I couldn’t use that callback outside of it.  So now I am doing a store.init() on load with its own callback (that only handles restored/revoked states), then doing another store.init() once the user gets into the “store” area of the app, that handles all the states.

It appears to be working.  Is there any problem with doing that?

While the plugin was not designed for you to call init() multiple times, I do not see any issue in doing so. If it is working during your testing than it should be fine.

Thanks again for the help, Preston.