Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to onActivityResult for startUpdateFlowForResult

What is the alternative to get callback for startUpdateFlowForResult in InAppUpdates instead of onActivityResult since it is deprecated?

like image 849
NIKUNJ GARG Avatar asked Nov 17 '25 02:11

NIKUNJ GARG


2 Answers

An updated Google doc has been made available: https://developer.android.com/guide/playcore/in-app-updates/kotlin-java

You can launch the update like this:

appUpdateManager.startUpdateFlowForResult(
    // Pass the intent that is returned by 'getAppUpdateInfo()'.
    appUpdateInfo,
    // an activity result launcher registered via registerForActivityResult
    activityResultLauncher,
    // Or pass 'AppUpdateType.FLEXIBLE' to newBuilder() for
    // flexible updates.
    AppUpdateOptions.newBuilder(AppUpdateType.IMMEDIATE).build()
)

And the activityResultLauncher is set up in your Activity like this:

private val activityResultLauncher = registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult()) { result ->
    val resultCode = result.resultCode
    when {
        resultCode == Activity.RESULT_OK -> {
            Log.v("MyActivity", "Update flow completed!")
        }
        resultCode == Activity.RESULT_CANCELED -> {
            Log.v("MyActivity", "User cancelled Update flow!")
        }
        else -> {
            Log.v("MyActivity", "Update flow failed with resultCode:$resultCode")
        }
    }
}
like image 54
ProjectDelta Avatar answered Nov 19 '25 18:11

ProjectDelta


We have to wait for Google Play team to migrate away from the deprecated APIs. You can follow this issue on Google's Issue Tracker.

like image 35
headsvk Avatar answered Nov 19 '25 17:11

headsvk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!