最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

What happens to Android Activities when they perform an in-app update? - Stack Overflow

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论