Two Simple ADB Commands for Android State Restoration Testing

When building Android apps, I frequently test two scenarios:
- Configuration Changes
- Process Death
Both affect UI state, but they exercise different parts of your app.
Testing Configuration Changes
A configuration change recreates the Activity while keeping the process alive. Typical examples include screen rotation, locale changes, and font scale changes.
The following command rotates the device to landscape, then back to portrait:
# Disable auto-rotation so the device stays in a fixed orientation
adb shell settings put system accelerometer_rotation 0 && \
# Rotate the device to landscape (Configuration Change occurs)
adb shell settings put system user_rotation 1 && \
# Wait for Activity recreation to complete
sleep 1 && \
# Rotate the device back to portrait (another Configuration Change)
adb shell settings put system user_rotation 0 && \
# Re-enable auto-rotation
adb shell settings put system accelerometer_rotation 1
Expected behavior:
Activity destroyed
↓
Activity recreated
↓
ViewModel survives
↓
UI state is restored
This is useful for verifying:
- rememberSaveable
- Activity recreation
- UI state restoration
- Navigation state restoration
Testing Process Death
Process death is a different scenario. The entire process is terminated, and Android later recreates it when the user returns to the app.
The following command simulates this flow:
# Send the app to the background
adb shell input keyevent KEYCODE_HOME && \
# Give the launcher time to become visible
sleep 1 && \
# Kill the app process while it is in the background
adb shell am kill com.benigumo.kaomoji && \
# Wait for the process to be fully terminated
sleep 1 && \
# Open the Recent Apps screen
adb shell input keyevent KEYCODE_APP_SWITCH && \
# Give the Recents UI time to appear
sleep 1 && \
# Tap the app card to restore the task and verify state restoration
adb shell input tap 500 1200
Expected behavior:
Process killed
↓
ViewModel destroyed
↓
Process recreated
↓
SavedStateHandle restored
↓
UI state is restored
This is useful for verifying:
- SavedStateHandle
- Process death recovery
- ViewModel restoration
- Navigation state restoration after process recreation
Configuration Change ≠ Process Death
One of the most common misconceptions is treating configuration changes and process death as the same thing.
Configuration Change
↓
Activity recreated
↓
ViewModel survives
Process Death
↓
Process killed
↓
ViewModel recreated
If you only test screen rotation, you’re not testing process death recovery.
Make sure to test both.