Reputation: 620
I'm using Android Play Core Library's new feature In-App Updates
.
So the documentation says that for a Flexible In-App Update, I need an InstallStateUpdatedListener
which would listen for when the update is downloaded in the background, and then we need to show a UI or in my case a Snackbar to the user, describing that the user now needs to install the already downloaded update. This works fine when I'm in the foreground for the whole time, but when I go to the background before the in-app update is downloaded and then return to the foreground of the app after some time, my app automatically gets updated without showing any UI to the user asking them to install the update. This should not happen ideally as per the docs.
I've tried removing all kind of listeners, commenting out the code which completes the update, but to no avail.
appUpdateManager = AppUpdateManagerFactory.create(getAppContext());
if (appUpdateInfo.updateAvailability() != UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
final InstallStateUpdatedListener listener =
new InstallStateUpdatedListener() {
@Override
public void onStateUpdate(InstallState installState) {
if (installState.installStatus() ==
InstallStatus.DOWNLOADED) {
showUpdateCompletedSnackbar();
}
}
};
appUpdateManager.registerListener(listener);
try {
Log.d("BaseApp","Starting Flexible in app update");
appUpdateManager.startUpdateFlowForResult(
appUpdateInfo,
AppUpdateType.FLEXIBLE,
getActivity(),
2000);
} catch (IntentSender.SendIntentException exception) {
Log.e("BaseApp",exception);
}
}
private static void showUpdateCompletedSnackbar() {
Snackbar snackbar =
Snackbar.make(getContainer(),
appContext.getString(R.string.in_app_update_snackbar_text),
Snackbar.LENGTH_INDEFINITE);
snackbar.setAction("INSTALL", new View.OnClickListener() {
@Override
public void onClick(View v) {
appUpdateManager.completeUpdate();
}
});
snackbar.setActionTextColor(
ContextCompat.getColor(getAppContext(), R.color.blue));
snackbar.show();
}
Upvotes: 2
Views: 1556
Reputation: 620
Okay, so actually the documentation was not that clear about this, but one caveat in the Flexible In-app update is that, once you start downloading the in-app update and you continue using the app, the update will download in the background and then will notify the user through a UI that the Update has been downloaded and we need to install the update (this showing of UI and all will be handled by the developer).
But the second case, of which I had an issue, was that what if, before the update is downloaded, I move my app to the background. In that case, if the update is downloaded while the app is in the background, then it will install the update too without informing the user to the new version and then when you take your app to the foreground, you'll see the updated app, instead of any UI.
The Flexible update was for this only, that if the user is using the app, the update will be downloaded in the background without the user having the trouble to close the app and updating it leaving the work which they were doing in the app, and then post the update is downloaded the user will have a choice to finally install the update using a UI shown to them whenever they want or when they complete their ongoing work in the app.
There are more caveats in the app and this medium article would be helpful for you all to see more of the edge cases https://proandroiddev.com/android-in-app-updates-common-pitfalls-and-some-good-patterns-9024988bbbe8
Upvotes: 3