I'm trying to understand what happens when an Activity calls for an in-app update because I've observed behavior I don't understand. I'll explain that behavior here.
I have two activities - LaunchActivity and UpdateActivity. LaunchActivity checks to see if an update is available before calling UpdateActivity. Here's how LaunchActivity checks for an update. This code is working as expected.
appUpdateInfoTask.addOnSuccessListener { appUpdateInfo ->
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE) {
if (appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
val intent = Intent(this, UpdateActivity::class.java)
startActivity(intent)
}
}
}
UpdateActivity has a button to begin the update process. Pressing that button executes this code.
appUpdateInfoTask.addOnSuccessListener { appUpdateInfo ->
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE) {
if (appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
appUpdateManager.startUpdateFlowForResult(appUpdateInfo, activityResultLauncher,
AppUpdateOptions.newBuilder(AppUpdateType.IMMEDIATE).build())
}
}
Pressing the button in UpdateActivity launches the Play Store overlay, which downloads and installs the update then relaunches the app as expected. When the app relaunches it opens to LaunchActivity even though UpdateActivity never received an onStop() or onDestroy(). Is this expected behavior or should the app relaunched into the UpdateActivity?
It seems redundant and inefficient to have UpdateActivity as an extra step in the process, so I moved the code from UpdateActivity into LaunchActivity and deleted UpdateActivity. This launches the same update flow as expected, but some error prevents the updated app from relaunching.
Just as with UpdateActivity, in this case LaunchActivity never received onStop() or onDestroy(). There is no logcat output from my application after LaunchActivity::onPause(). And after the update, LaunchActivity::onCreate() never gets called.
What the user sees in this second case is an update completing then dropping back to the Home Screen. I think there's something special going on with an activity when it calls startUpdateFlowForResult() but I've not been able to figure out what that is. I'm hoping people here may be able to provide insight or suggestions.