FlareStart
HomeNewsHow ToSources
FlareStart

Where developers start their day. All the tech news & tutorials that matter, in one place.

Quick Links

  • Home
  • News
  • Tutorials
  • Sources
  • Privacy Policy

Connect

© 2026 FlareStart. All rights reserved.

Back to articles
ViewModel SavedStateHandle Guide — Surviving Process Death in Android
How-ToTools

ViewModel SavedStateHandle Guide — Surviving Process Death in Android

via Dev.tomyougaTheAxo1mo ago

What You'll Learn How to use SavedStateHandle to preserve ViewModel state across process death. Why SavedStateHandle? Regular ViewModel variables live in memory only — they're lost on process death. SavedStateHandle saves state via Bundle, surviving process death and restoration. Basic Usage class SearchViewModel ( private val savedStateHandle : SavedStateHandle ) : ViewModel () { val query : StateFlow < String > = savedStateHandle . getStateFlow ( "query" , "" ) val selectedTab : StateFlow < Int > = savedStateHandle . getStateFlow ( "selectedTab" , 0 ) fun updateQuery ( newQuery : String ) { savedStateHandle [ "query" ] = newQuery } fun selectTab ( index : Int ) { savedStateHandle [ "selectedTab" ] = index } } Navigation Arguments class UserDetailViewModel ( savedStateHandle : SavedStateHandle ) : ViewModel () { private val userId : String = checkNotNull ( savedStateHandle [ "userId" ]) init { loadUser ( userId ) } } With Hilt @HiltViewModel class TodoViewModel @Inject constructor ( p

Continue reading on Dev.to

Opens in a new tab

Read Full Article
19 views

Related Articles

I have blogged about the difference between code coverage and test coverage and why it matters to distinguish between these 2.
How-To

I have blogged about the difference between code coverage and test coverage and why it matters to distinguish between these 2.

Dev.to Beginners • 1d ago

The origin story of Apple’s long-running relationship with FoxConn
How-To

The origin story of Apple’s long-running relationship with FoxConn

The Verge • 1d ago

How to Optimize Big Data Platform Costs Across the Data Lifecycle
How-To

How to Optimize Big Data Platform Costs Across the Data Lifecycle

Hackernoon • 1d ago

Switzerland — Best Crypto Exchange (2026)
How-To

Switzerland — Best Crypto Exchange (2026)

Dev.to Beginners • 1d ago

Cursor Your Dream, Part 2: How to Move From First Prompt to First Working App
How-To

Cursor Your Dream, Part 2: How to Move From First Prompt to First Working App

Hackernoon • 2d ago

Discover More Articles