DEV Community

Cover image for Persistent vs disposable Android environments: when test and app state should survive between runs
KSENIIA SHILOVA
KSENIIA SHILOVA

Posted on Edited on

Persistent vs disposable Android environments: when test and app state should survive between runs

Updated November 2026

A persistent Android environment for testing keeps app data, logins and device state between runs. A disposable one starts clean every time. Clean state gives you repeatable results and isolates failures. Persistent state lets you test what real users carry: sessions, caches, upgrades and accounts with history. Most teams need both. The useful question is which tests belong where, not which approach wins.

What do disposable and persistent mean for Android test environments?

Disposable means the device or its data is thrown away after each run. Persistent means the next run starts where the last one stopped. In practice there’s a third option in between: restoring a known saved state.

Disposable. Each run gets a fresh device or a wiped one. Firebase Test Lab is a clear example. For physical devices, it removes app data and resets system settings after every test run, and it flashes devices with a custom recovery image where possible. For virtual devices, it deletes each instance after use, so every run gets a new one.

Restored. An emulator snapshot puts the device back to a saved point. By default, each AVD saves a Quick Boot snapshot on exit and loads it on start. Google says a snapshot boot can be up to 10 times faster than a cold boot.

Persistent. The device keeps everything. That’s the default for a physical phone on your desk. It’s also true of a plain emulator: Android’s docs say the virtual device keeps the app and its data across restarts in a user data partition until you wipe it. Cloud Android phones work the same way, hosted remotely.

So “emulator” doesn’t mean disposable. How you start it decides:

`bash
Disposable: reset the AVD to factory defaults
emulator -avd Pixel_API_35 -wipe-data

Cold boot, but save state on exit
emulator -avd Pixel_API_35 -no-snapshot-load

Restored: boot from snapshot, don't save changes
emulator -avd Pixel_API_35 -no-snapshot-save`

The same choice exists one level down, inside a test suite. Android Test Orchestrator runs each test in its own Instrumentation instance. With clearPackageData, it runs pm clear after every test, so app state is wiped between tests:

groovy
android {
defaultConfig {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: 'true'
}
testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
}

Google notes the trade-off: the orchestrator restarts the app after each test, which can add execution time.

How do the options compare?
| | Emulator, wiped each run | Emulator snapshot | Device farm session | Physical phone | Cloud Android phone |
|---|---|---|---|---|---|
| Reset behaviour | Factory reset with -wipe-data | Back to a saved point on each start | Device reset or new instance after every run | None unless you reset it | None unless you reset it |
| Setup time per run | Boot, install, log in, every run | Fast boot, then whatever the snapshot lacks | Device allocation, install, log in, every run | Near zero once set up | Start the phone, then near zero |
| State carried over | Nothing | Exactly what the snapshot holds | Nothing | Everything | Everything |
| Sources of flaky runs | Slow boots, first-run dialogs, setup steps | Stale or invalid snapshots | Queue times, device updates, setup steps | Leftover state, expired sessions, auto-updates | Leftover state, expired sessions, your connection |
| Cost model | Your own compute | Your own compute | Per minute of device time | Buying and maintaining hardware | Subscription plus running time |

The flaky-run row is from my own runs, not from vendor docs. Your list will look different, so treat it as a starting point.

Where does clean state help?

Anywhere the test should prove something from zero. A clean device gives every run the same starting point, so a failure points at the code, not at what the last test left behind.

Clean state fits:

  • First-run flows. Onboarding, permissions prompts, sign-up and first login.

  • Unit-like instrumented tests. Each test should own its setup and teardown.

  • Parallel CI runs. Disposable devices can’t contaminate each other.

  • Bisecting a failure. Re-run the same commit on a fresh device and compare.

  • Install and packaging checks. A clean install catches missing assets and migrations that only run once.

The cost is setup on every run. Each test pays for boot, install and login. Clean devices also hide a whole class of bugs, because real users never start clean.

Where does persistent state help?

Anywhere the bug only appears with history. Real users have been logged in for months. They’ve upgraded the app six times and have caches, drafts and notification settings piling up. A device that keeps state can reproduce that, and a wiped one can’t.

Persistent state fits:

  • Upgrade paths. Install version N, use it, then install N+1 over it and check migrations.

  • Session behaviour. Token refresh, “remember me”, re-authentication after days, not seconds.

  • Long-running accounts. Flows that depend on what an account has done before: streaks, history, saved settings.

  • Slow setup. If logging in or seeding data takes minutes, paying that once instead of on every run adds up.

  • Manual and exploratory testing. A tester picks up exactly where they left off yesterday.

The cost is drift. Every run changes the device a little. Without care, a test passes because of state you forgot was there.

Which persistent options are there?

  • Physical phones. Real hardware and SIM. Someone has to keep them charged, updated and on the network.

  • Emulators you don’t wipe. Cheap and local, tied to one machine.

  • Cloud Android phones. Persistent devices in a data centre that you reach over the network. Multilogin, a cloud Android phone platform for multi-account management, is one example. Its help center says each cloud phone keeps its own app data, login history, device details and sessions, and supports automation with ADB and Appium. Its cloud phones can’t receive SMS or calls, so an OTP step needs a separate number or a test account without one. They also need a reliable connection, since you work through a stream. Other providers include GeeLark, DuoPlus and VMOS Cloud.

How do you mix both?

Give each test a clear contract: either it needs a clean device, or it needs a device in a known persistent state. Then route it to the right pool.

A setup that tends to hold up:

  • Default to disposable in CI. Most instrumented tests should run clean, with Orchestrator’s clearPackageData or wiped emulators.

  • Keep a small persistent pool for history-dependent tests. Upgrades, long sessions, accounts with history. Tag those tests so they never land on a disposable device.

  • Record state before each persistent run. It turns “flaky” into “explained”:
    bash
    adb shell dumpsys package com.example.app | grep versionName # app version on the device
    adb shell pm list packages -3 # other installed apps
    adb shell settings get global auto_time # a setting your tests rely on

  • Reset persistent devices on a schedule, not every run. Weekly or per release, back to a documented baseline.

  • Pin app updates on persistent devices. An auto-update overnight is a classic source of failures that nobody can reproduce.

  • Use snapshots as the middle ground. A logged-in snapshot gives you persistent-looking state that you can restore exactly.

No single pool is right for every suite. A team shipping a calculator app may never need persistent devices. A team shipping a banking or social app probably can’t skip them.

FAQ

What is a persistent Android environment for testing?
It’s a device that keeps app data, logins and settings between runs, such as a physical phone, an emulator you don’t wipe, or a cloud Android phone. Multilogin is one cloud option: each cloud phone keeps its own app data and login history between sessions. It suits tests that depend on history, like upgrades and long sessions.

Are emulator snapshots disposable or persistent?
Both, depending on how you use them. Loading a snapshot without saving changes (-no-snapshot-save) restores the same state every run, which behaves like disposable. Letting Quick Boot save on exit carries state forward, which behaves like persistent.

Does pm clear make a device clean?
It clears the app’s own data. Other apps, device settings and anything stored on your backend stay as they were. For a truly clean start, wipe the device or use a fresh instance.

How do I stop persistent devices from causing flaky tests?
Record the device’s state before each run, pin app updates and reset to a baseline on a schedule. Keep history-dependent tests tagged so they only run where history is expected.

Can I automate a cloud Android phone in CI?
Usually, yes. Multilogin’s help center lists ADB and Appium for its cloud phones. Plan for two things: your CI runner needs a stable connection to the phone, and login flows can’t rely on SMS reaching the device.

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

Really clear framing — the point that "emulator doesn't mean disposable, how you start it decides" is the one most teams miss. The -no-snapshot-save middle ground is my favorite part: a logged-in snapshot gives you persistent-looking state for upgrade and session tests, but you can still restore it exactly. One thing I'd add: pinning app updates on persistent devices matters even more in practice, because an overnight auto-update doesn't just break a run, it breaks it in a way nobody can reproduce the next morning. The adb shell dumpsys package ... | grep versionName check before each run is a cheap guard for exactly that.