AndroidSavedStateDelegate
Android implementation of SavedStateDelegate using SavedStateHandle.
What is SavedStateHandle?
Part of Android's ViewModel architecture
Automatically persists data across process death
Survives configuration changes (rotation, etc.)
Backed by Bundle (same mechanism as onSaveInstanceState)
How Process Death Recovery Works:
User opens permission dialog
Android kills process to reclaim memory
SavedStateHandle automatically saves GrantHandler state
User returns to app
Android recreates process
SavedStateHandle restores state
Dialog reappears with same content
Usage:
class MyViewModel(
private val grantManager: GrantManager,
private val savedStateHandle: SavedStateHandle // Injected by ViewModel
) : ViewModel() {
val cameraGrant = GrantHandler(
grantManager = grantManager,
grant = AppGrant.CAMERA,
scope = viewModelScope,
savedStateDelegate = AndroidSavedStateDelegate(savedStateHandle)
)
}Content copied to clipboard
Benefits:
Zero boilerplate for users
Automatic state restoration
Works with Jetpack Compose + Navigation
Type-safe with SavedStateHandle
Parameters
savedStateHandle
The SavedStateHandle from ViewModel