简体   繁体   English

应用内更新(即时)不重启应用

[英]In-App update (IMMEDIATE) not restarting an app

Facing an issue with IMMEDIATE app update mode.面临即时应用程序更新模式的问题。 After successful completion of app update, everything is closed and not restarting the app.成功完成应用程序更新后,所有内容都会关闭并且不会重新启动应用程序。 That is the issue.这就是问题所在。 But android documentation says:但是 android 文档说:

A full screen user experience that requires the user to update and restart the app in order to continue using the app.全屏用户体验,要求用户更新并重新启动应用程序才能继续使用该应用程序。 This UX is best for cases where an update is critical for continued use of the app.此 UX 最适用于更新对于继续使用应用程序至关重要的情况。 After a user accepts an immediate update, Google Play handles the update installation and app restart.在用户接受立即更新后,Google Play 会处理更新安装和应用重启。

implementation 'com.google.android.play:core:1.9.1'
implementation 'com.google.android.play:core-ktx:1.8.1'

code代码

class MainActivity : AppCompatActivity() {

    companion object {
        const val UPDATE_REQUEST_CODE = 112
        const val TAG = "MainActivity"
    }

    private var appUpdateManager: AppUpdateManager? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        findViewById<TextView>(R.id.tv_text).text = "Version " + BuildConfig.VERSION_NAME

        // Returns an intent object that you use to check for an update.
        appUpdateManager = AppUpdateManagerFactory.create(this)
    }

    private val listener: InstallStateUpdatedListener =
        InstallStateUpdatedListener { installState ->
            if (installState.installStatus() == InstallStatus.DOWNLOADED) {
                // After the update is downloaded, show a notification
                // and request user confirmation to restart the app.
                Log.d(TAG, "An update has been downloaded")
            } else if (installState.installStatus() == InstallStatus.INSTALLED) {
                Log.d(TAG, "An update has been installed")
            }
        }

    override fun onStart() {
        super.onStart()
        checkAppVersionNew()
    }

    private fun checkAppVersionNew() {
        val appUpdateInfoTask = appUpdateManager!!.appUpdateInfo
        appUpdateInfoTask.addOnSuccessListener { result: AppUpdateInfo ->
            if (result.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && result.isUpdateTypeAllowed(
                    AppUpdateType.IMMEDIATE
                )
            ) {
                try {
                    Log.d(TAG, "An update available")
                    appUpdateManager!!.startUpdateFlowForResult(
                        result,
                        AppUpdateType.IMMEDIATE,
                        this,
                        UPDATE_REQUEST_CODE
                    )
                } catch (e: SendIntentException) {
                    Log.d(TAG, "SendIntentException $e")
                    e.printStackTrace()
                }
            }
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        if (requestCode == UPDATE_REQUEST_CODE) {
            when (resultCode) {
                RESULT_OK -> {
                    Log.d(TAG, "Update success")
                }
                RESULT_CANCELED -> {
                    Log.d(TAG, "Update cancelled")
                }
                ActivityResult.RESULT_IN_APP_UPDATE_FAILED -> {
                    Log.d(TAG, "Update failed")
                }
            }
        }
    }
}

I faced this issue and after 2 days I added我遇到了这个问题,2 天后我添加了

android:launchMode="singleTask"

to the launcher Activity And I used到启动器 Activity 我用过

ProcessPhoenix.triggerRebirth(this)

From ProcessPhoenix library And then the app restarted after updating.来自 ProcessPhoenix 库 然后应用程序在更新后重新启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将应用程序更新标记为即时或灵活(应用程序内更新API) - How to mark app update as Immediate, or Flexible(in-app updates API) Android应用内更新API-&gt;立即更新问题 - Android In-app update API -> Immediate update problem 如何实现灵活且即时的应用内更新 - How to implement both flexible and immediate In-App Update 应用内更新:决定在灵活更新和立即更新之间进行选择的策略 - In-App Updates : decide a strategy to choose between Flexible and Immediate update 应用内更新会重新启动过时的版本,而不是新安装的版本 - in-app update restarting the obsolete version instead of the newly installed version appUpdateInfo.isUpdateTypeAllowed (AppUpdateType.IMMEDIATE) 在 Android In-App Update API 中的作用是什么? - What purpose does appUpdateInfo.isUpdateTypeAllowed (AppUpdateType.IMMEDIATE) serve in Android In-App Update API? 应用内更新通知 - In-app update notification 如何在应用程序更新中实现“立即”? - How to implement "IMMEDIATE" In app update? Android - 应用内更新。 在哪里指定更新(上传到 playstore 的新 apk)应该是 IMMEDIATE 还是 FLEXIBLE 类型更新? - Android - In-App Updates. Where to specify whether an Update(new apk uploaded to playstore) should be an IMMEDIATE or FLEXIBLE type update? 应用程序终止后立即处理应用程序内更新 - Handling Immediate In App Update after App termination
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM