Developer Console

Appstore Billing Compatibility SDK Best Practices

Follow these best practices when integrating your app with the Appstore Billing Compatibility SDK.

Improve app startup time

Calls to the Appstore Billing Compatibility APIs on app startup can increase the time it takes for the app to launch, resulting in a poor customer experience. As a best practice, the Amazon Appstore recommends that you make these server-side calls in the background to avoid delays when your app loads.

Avoid blocking the UI from loading

In the Fetch purchases integration guide, you are instructed to call queryPurchasesAsync() in the onResume() method to query customers' purchases. This API requires a server-side call to Amazon's server. Unlike the queryPurchasesAsync() method in Google Play Billing, the queryPurchasesAsync() method in the Appstore Billing Compatibility SDK makes a network call, which affects the time it takes for the listener callback to occur.

To prevent startup delays, don't block your UI from loading while your app waits for a response from Amazon's server. Instead, the Appstore recommends that you use the last purchase state that you have cached in your back-end server or in the app.

After you receive a response from queryPurchasesAsync(), update your app's UI asynchronously to reflect any changes in the customer's purchase data.

Use the following diagrams to help visualize what happens when making Appstore Billing Compatibility API calls while an app loads.

Typical flow: Appstore Billing Compatibility API calls block the UI from loading

This diagram shows the steps from app launch to app UI load when Appstore Billing Compatibility API calls block the UI from loading.

The following steps describe the flow
  1. The user clicks on the app to launch it.
  2. A black screen is displayed while the app UI loads.
  3. The app begins to start up. In onResume(), the app calls queryPurchasesAsync() on the UI thread. A network call is made to fetch purchase details. During this time, the user continues to see a black screen.
  4. The app grants access of the purchased items to the customer.
  5. The app continues loading the UI by showing the splash screen.

In this typical flow, a customer sees a black screen for several seconds as the Appstore Billing Compatibility API calls are made, which gives the perception that app launch is slow.

This diagram shows the steps from app launch to app UI load, when the Appstore Billing Compatibility API calls are made in the background.

The following steps describe the flow
  1. The app stores past purchase data in a back-end server or cache.
  2. The user clicks on the app to launch it.
  3. The app displays the splash screen and loads the UI based on the past data. The app does not check for purchase data from the server.
  4. In the background, the app calls queryPurchasesAsync(). The UI isn't blocked from loading.

    The queryPurchasesAsync() API takes a PurchasesResponseListener object as parameter. You can add logic to update the app UI in the PurchasesResponseListener object's onQueryPurchasesResponse() method.

  5. Synchronize your cache (or back end) with the new data.
  6. If needed, update or switch the UI to block or unblock the user from accessing content.

Last updated: Oct 14, 2024