Google has come up with the solution to this problem. It offers an in-app update feature to update the app without interacting/opening the play store. With this feature, a user can download the latest features while using the app. So let’s dive in to see how we can use this feature.
The in-app update is available in Android Play Core library, that shows prompt to the user for an in-app update. There are two different ways in which we can prompt our users that an update is available.
If the core functionality of the app doesn’t get affected by the released features then you can use the Flexible Update flow. It allows user to download the update in the background. Once downloading is done, user will be asked to restart the app. Doing so will update the app during the restart process. The benefit of using this Flexible flow is that a user can use the app until the download process is finished. So there is no block time while using the app. User can still use the features as the downloading process is being done in the background.
If the core functionality of the app is highly dependent on the released features then you can use the Immediate Update flow. In this feature, a dialog will be prompted to ask the user for downloading and installing updates. The user can’t use the app until the downloading, installing and restarting the app.
Checking if an update is available or not –
For a good user experience, we should always ask the user to update the app only if updates are available. We can check if an update is available or not from the backend.
For that you can use the AppUpdateManager, which will give the AppUpdateInfo object that contains the information about if we need to show the update dialog or not. The updateAvailability method returns these values for the update state :
Start an update –
Once you have checked for the updates and in case of updates are available then you can use
startUpdateFlowForResults() to update the app.
We will get the following request codes in onActivityResult.
RESULT_CANCELED : This will indicate that user has denied/canceled for the update.
RESULT_OK : This will indicate that user has accepted the update.
RESULT_IN_APP_UPDATE_FAILED : This will indicate that there is some problems occurred during the update.
So now we know how to use in-app update feature to update the app. It’s a good practice to use the Flexible Flow to update the app when there are very few updates and it doesn’t affect the core functionality of your app. However, you have to make a decision on which flow to use as per your requirements and the kind of app you are making. I hope I was clear and concise in my blog and I hope now you have an understanding of how in-app update API work in Android.