IAP Best Practice - Improve App Startup Time
Calling In-App Purchasing (IAP) APIs on app startup can significantly increase the time it takes for the app to launch, resulting in a poor customer experience. As a best practice, the Amazon Appstore recommends making these server-side calls in the background to avoid delays when your app loads.
Avoid blocking the UI from loading
In Integrate the IAP API with your app, you are instructed to call getUserData()
and getPurchaseUpdates()
in the onResume()
method to query a customer's entitlement status. These APIs require server-side calls to Amazon's back-end server. The first call is uncached and can take up to two seconds to execute, which can slow down your app startup time. Subsequent calls are cached and won't cause this delay.
To prevent startup delays, don't block your UI from loading while your app waits for a response from Amazon's servers. Instead, the Appstore recommends to use the last entitlement state that you have cached in your back-end server. This can be from the last time the user logged in or accessed the app, or from the last time Real Time Notifications was updated.
After you have received a response from getUserData()
and getPurchaseUpdates()
, query Amazon's Receipt Verification Service for Appstore SDK IAP (RVS) to get the customer's current entitlement status. Doing this avoids synchronization issues. Cache the data you receive on your back-end server. You can then update your app's UI asynchronously to reflect any changes in the customer's entitlement status.
Architectural diagrams
Use these diagrams to help visualize what happens when making IAP calls while an app loads.
Typical flow: IAP calls block the UI from loading
This diagram shows the steps from app launch to app UI load when IAP calls block the UI from loading.
Typical flow description
- The user clicks on the app to launch it.
- A black screen is displayed while the app UI loads.
- The app begins to start up. In
onResume()
, the app callsgetUserData()
followed bygetPurchaseUpdates()
on the UI thread. Loading is delayed by approximately two seconds. During this time, the user continues to see a black screen. - The app calls RVS and checks entitlement status with the returned receipts.
- If the entitlement status is active, the app grants access to the customer.
- 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 IAP calls are made, which gives the perception that app launch is slow.
Recommended flow: IAP calls are made in the background
This diagram shows the steps from app launch to app UI load, when the IAP calls are made in the background.
Recommended flow description
- Cache, or store in your back end, the previously used entitlement data for a minimum of 30 days.
- The user clicks on the app to launch it.
- The app displays the splash screen and loads the UI based on the cache data. The app does not check for entitlement data from the server.
- The app makes the
getUserData()
andgetPurchaseUpdates()
calls in the background. Loading the UI is not blocked. - When
getUserData()
andgetPurchaseUpdates()
calls return, pass the receipts to your back-end server, which calls RVS to confirm the validity of the receipt. - If the receipt is valid, synchronize your cache (or back end) with the new data.
- If needed, update or switch the UI to block or unblock the user from accessing content.
Last updated: Feb 02, 2023