Staged rollouts and in-app updates

Learn Google Play staged rollouts and the Android In-App Updates API: rollout percentages, halting a release, and flexible vs immediate AppUpdateManager flows. About 25 minutes.

Why it matters

  • A staged rollout limits how many users a bad release reaches. Halting at 5% is an incident; shipping to 100% is an outage.
  • Rollout decisions are made from data: Android vitals in Play Console (crash and ANR rates per release) and your crash reporting tool.
  • The Play In-App Updates API (AppUpdateManager) lets you ask users to update without leaving the app, and lets you insist when a fix is critical.
  • Interviewers test how you manage release risk: what halting does and does not do, and how you get a fix out fast.

The simple explanation

  • A chef serves a new dish to a few tables first and only adds it to the menu if nobody sends it back.
  • A dam operator opens a gate a little at a time instead of all at once.

What is a staged rollout on Google Play? It is a production release that Play delivers to a percentage of users instead of everyone. You choose the percentage in Play Console (or with the userFraction field in the Play Developer API), watch Android vitals and crash reports, then increase it until the release is complete. If something is wrong you halt the rollout: no new users get it, but users who already updated keep it, because Play cannot downgrade an installed app. The real fix is a new release with a higher versionCode. A halted rollout can also be resumed.

While a staged rollout controls who can get the new version, the Play In-App Updates API controls how users already on an older version are asked to update. There are two types:

TypeUser experienceTypical use
AppUpdateType.IMMEDIATEfull-screen Play UI; the user waits while the update downloads and installs, and the app restartscritical fixes the app cannot run without
AppUpdateType.FLEXIBLEthe user agrees, the download runs in the background while they keep using the app; the app then asks to restartmost feature and bug-fix updates

You use AppUpdateManager (from AppUpdateManagerFactory.create(context)) to read AppUpdateInfo, check updateAvailability() and isUpdateTypeAllowed(type), then call startUpdateFlowForResult(appUpdateInfo, launcher, AppUpdateOptions.newBuilder(type).build()) with a launcher from registerForActivityResult(StartIntentSenderForResult()). For a flexible update you register an InstallStateUpdatedListener, and when the status is InstallStatus.DOWNLOADED you ask the user to restart and call completeUpdate().

To decide between the two, use updatePriority() (0 to 5, set per release with inAppUpdatePriority in the Play Developer API) and clientVersionStalenessDays() (days since the update became available to this user).

Notes

  • Staged rollouts are set in Play Console or the Play Developer API, not in app code.
  • Halting stops new installs of that release. Users who already updated keep it; ship a fixed release with a higher versionCode.
  • Users only see an in-app update when Play would offer them that version, so during a 10% rollout most users get UPDATE_NOT_AVAILABLE.
  • Add com.google.android.play:app-update and app-update-ktx (the Kotlin extensions). The old monolithic Play Core library is replaced by these per-feature libraries.
  • Start an update with startUpdateFlowForResult(appUpdateInfo, activityResultLauncher, AppUpdateOptions). Each AppUpdateInfo can start a flow only once; request a fresh one to retry.
  • The launcher gets RESULT_OK, RESULT_CANCELED (the user declined or cancelled) or ActivityResult.RESULT_IN_APP_UPDATE_FAILED. Even an immediate update can be cancelled by the user, so the app must decide what to do next.
  • Flexible: when the status is InstallStatus.DOWNLOADED, Play does not restart the app for you. Show a prompt and call appUpdateManager.completeUpdate().
  • In onResume, check for a flexible update stuck in DOWNLOADED and for an immediate update in UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS, which you resume.
  • updatePriority() comes from inAppUpdatePriority set when rolling out a release through the Play Developer API; it cannot be changed later.
  • Test with internal app sharing or an internal testing track on a device whose account can see the update. inAppUpdatePriority is not supported for internal app sharing uploads. For unit tests, FakeAppUpdateManager simulates the flow.

Code example

An Activity that checks for an update, picks immediate for high-priority releases and flexible otherwise, and finishes a downloaded flexible update.

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.result.contract.ActivityResultContracts
import com.google.android.play.core.appupdate.AppUpdateManager
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
import com.google.android.play.core.appupdate.AppUpdateOptions
import com.google.android.play.core.install.InstallStateUpdatedListener
import com.google.android.play.core.install.model.AppUpdateType
import com.google.android.play.core.install.model.InstallStatus
import com.google.android.play.core.install.model.UpdateAvailability
 
class MainActivity : ComponentActivity() {
 
    private lateinit var appUpdateManager: AppUpdateManager
 
    private val updateLauncher =
        registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult()) { result ->
            if (result.resultCode != RESULT_OK) {
                // Declined, cancelled or failed: let the user continue and ask again later.
            }
        }
 
    private val installListener = InstallStateUpdatedListener { state ->
        if (state.installStatus() == InstallStatus.DOWNLOADED) {
            showRestartPrompt()
        }
    }
 
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        appUpdateManager = AppUpdateManagerFactory.create(this)
        appUpdateManager.registerListener(installListener)
        checkForUpdate()
    }
 
    private fun checkForUpdate() {
        appUpdateManager.appUpdateInfo.addOnSuccessListener { info ->
            if (info.updateAvailability() != UpdateAvailability.UPDATE_AVAILABLE) {
                return@addOnSuccessListener
            }
            val type = when {
                info.updatePriority() >= 4 && info.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE) ->
                    AppUpdateType.IMMEDIATE
                info.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE) -> AppUpdateType.FLEXIBLE
                else -> return@addOnSuccessListener
            }
            appUpdateManager.startUpdateFlowForResult(
                info,
                updateLauncher,
                AppUpdateOptions.newBuilder(type).build()
            )
        }
    }
 
    override fun onResume() {
        super.onResume()
        appUpdateManager.appUpdateInfo.addOnSuccessListener { info ->
            if (info.installStatus() == InstallStatus.DOWNLOADED) {
                showRestartPrompt()
            } else if (
                info.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS
            ) {
                // Resume an immediate update the app started earlier.
                appUpdateManager.startUpdateFlowForResult(
                    info,
                    updateLauncher,
                    AppUpdateOptions.newBuilder(AppUpdateType.IMMEDIATE).build()
                )
            }
        }
    }
 
    override fun onDestroy() {
        appUpdateManager.unregisterListener(installListener)
        super.onDestroy()
    }
 
    private fun showRestartPrompt() {
        // Show a snackbar or dialog with a "Restart" action that calls:
        // appUpdateManager.completeUpdate()
    }
}
  • The launcher is registered as a property, before the Activity starts, which is what registerForActivityResult requires.
  • updatePriority() lets the release decide: a priority of 4 or 5 (set with the Play Developer API) gets the immediate flow; anything else gets flexible.
  • completeUpdate() is called only from the user's restart action; Play does not restart the app for a flexible update on its own.
  • The onResume check covers the user leaving the app mid-update: a finished flexible download is offered again, and an interrupted immediate update is resumed.

Run the idea in plain Kotlin

enum class InstallStatus { PENDING, DOWNLOADING, DOWNLOADED, INSTALLED }

fun inRollout(userId: Int, percent: Int): Boolean = userId % 100 < percent

fun chooseType(priority: Int, stalenessDays: Int?): String = when {
  priority >= 4 -> "IMMEDIATE"
  priority >= 2 || (stalenessDays ?: -1) >= 7 -> "FLEXIBLE"
  else -> "NONE"
}

fun main() {
  val users = listOf(3, 42, 118, 260)
  for (percent in listOf(5, 50)) {
      val offered = users.filter { inRollout(it, percent) }
      println("Rollout " + percent + "%: update offered to users " + offered)
  }

  println("priority 5 -> " + chooseType(5, 1))
  println("priority 2 -> " + chooseType(2, 1))
  println("priority 0, 10 days stale -> " + chooseType(0, 10))
  println("priority 0, 1 day stale -> " + chooseType(0, 1))

  val listener: (InstallStatus) -> Unit = { status ->
      if (status == InstallStatus.DOWNLOADED) {
          println("DOWNLOADED: show Restart prompt -> completeUpdate()")
      } else {
          println("status " + status)
      }
  }
  listOf(InstallStatus.PENDING, InstallStatus.DOWNLOADING, InstallStatus.DOWNLOADED).forEach(listener)
}

Expected output:

Rollout 5%: update offered to users [3]
Rollout 50%: update offered to users [3, 42, 118]
priority 5 -> IMMEDIATE
priority 2 -> FLEXIBLE
priority 0, 10 days stale -> FLEXIBLE
priority 0, 1 day stale -> NONE
status PENDING
status DOWNLOADING
DOWNLOADED: show Restart prompt -> completeUpdate()

In production

Startup crash shipped to everyone
  • A release crashed on startup on one older Android version because a new dependency called an API that does not exist there.
  • The release went straight to 100% of production, so every affected user got it within hours.
  • Halting the release stopped new installs, but users who had already updated were stuck with the crash until a fix shipped.
The fix
  • The team fixed the call with an API level check, raised versionCode, tested on the internal track, then released to production as a staged rollout.
  • The release checklist now starts every production release at a small percentage and only increases it after checking Android vitals for the new version.
  • The fix release was given a high inAppUpdatePriority, so the app showed affected users the immediate update flow.
Flexible update that never installed
  • The app started flexible updates, and users accepted them, but the installed version barely changed over weeks.
  • The listener only logged download progress; nothing handled InstallStatus.DOWNLOADED, so the downloaded update waited on the device and took up storage.
The fix
  • On DOWNLOADED, the app now shows a snackbar with a Restart action that calls appUpdateManager.completeUpdate().
  • onResume checks appUpdateInfo.installStatus() and shows the same prompt if a downloaded update is waiting.
  • A unit test with FakeAppUpdateManager drives the flow to DOWNLOADED and checks that the prompt appears.

Common mistakes

  • Skipping staged rollouts for small changes. A one-line change can still crash on startup. Start every production release at a small percentage.
  • Using IMMEDIATE for every update. Blocking users for a minor update is frustrating. Keep immediate for releases the app cannot run without, and choose using updatePriority().
  • Not watching vitals during the rollout. A rollout only helps if someone checks crash and ANR rates for the new version before increasing it.
  • Forgetting the DOWNLOADED state. A flexible update downloads but never installs until you call completeUpdate().
  • Assuming halting rolls users back. It only stops new installs. Plan the fix as a new release with a higher versionCode.
  • Using the old Play Core library or request-code APIs. Use the app-update library and startUpdateFlowForResult with an ActivityResultLauncher.

Interview questions

Answer out loud first. Then reveal the answer and compare it at each depth.

“What is the difference between a staged rollout and an in-app update?”

“How would you handle a critical security issue that needs users to update quickly?”

“A 10% staged rollout shows a high crash rate. What do you do?”

“Why might a flexible update never get installed?”

Quiz

Which in-app update type fits a non-critical UI polish release?

What is the main purpose of a staged rollout?

You halt a staged rollout. What happens to users who already installed the new version?

During a flexible update, the listener reports InstallStatus.DOWNLOADED. What should the app do?

0 of 4 answered

Mini task

Add flexible in-app updates to your app (15 min)

  1. Add com.google.android.play:app-update and com.google.android.play:app-update-ktx to your app module.

  2. In your main Activity, create the AppUpdateManager with AppUpdateManagerFactory.create(this) and register a launcher with registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult()).

  3. Check appUpdateInfo: if updateAvailability() is UPDATE_AVAILABLE and isUpdateTypeAllowed(AppUpdateType.FLEXIBLE), call startUpdateFlowForResult(info, launcher, AppUpdateOptions.newBuilder(AppUpdateType.FLEXIBLE).build()).

  4. Register an InstallStateUpdatedListener. On InstallStatus.DOWNLOADED, show a snackbar whose Restart action calls completeUpdate(). Unregister it in onDestroy.

  5. In onResume, show the same snackbar if installStatus() is DOWNLOADED.

  6. Test: upload a build to internal app sharing, install it, then open an internal app sharing link for a build with a higher versionCode (or write a unit test with FakeAppUpdateManager that calls setUpdateAvailable, userAcceptsUpdate, downloadStarts and downloadCompletes).

Done condition: the app offers a flexible update, the user keeps using it during the download, and the Restart prompt installs the update, including after leaving and returning to the app.

Next: Versioning and release management