11

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:

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. After a user accepts an immediate update, Google Play handles the update installation and app restart.

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")
                }
            }
        }
    }
}
sj.94
  • 123
  • 1
  • 5
  • Did you find a resolution on this? – Rowan Gontier May 17 '21 at 07:54
  • Having same issue, any update ? Even doing a forced restart doesn't restarts the app with Immediate flow – Fawaz Aug 13 '21 at 12:21
  • same issue from a long – Akarsh M Sep 09 '21 at 11:24
  • Any solution got for this ? @RowanGontier – Akarsh M Sep 09 '21 at 11:25
  • @Fawaz Any solution you get? – Akarsh M Sep 09 '21 at 11:26
  • @AkarshM not yet, waiting for Google to fix it. At the moment you can just use flexible flow and restart programatically on update installed event. – Fawaz Sep 10 '21 at 07:06
  • Looks like there is a bug. Some of the Samsung devices restart like Samsung S9. I tried with Samsung Note 10 and Pixel 3XL it doesn't restart the application. – Viks Sep 12 '21 at 03:45
  • @Fawaz bit strange , from al long this issue still open I have seen few application and their immediate works fine, dont know how ? – Akarsh M Sep 20 '21 at 07:10
  • Does this answer your question? [Android In App Update not installing APK after downloading APK in immediate mode](https://stackoverflow.com/questions/58553644/android-in-app-update-not-installing-apk-after-downloading-apk-in-immediate-mode) – Anthony Cannon Oct 01 '21 at 11:38

1 Answers1

0

I faced this issue and after 2 days I added

android:launchMode="singleTask"

to the launcher Activity And I used

ProcessPhoenix.triggerRebirth(this)

From ProcessPhoenix library And then the app restarted after updating.

Dharman
  • 30,962
  • 25
  • 85
  • 135