ProAndroidDev
Read post

Understanding retain: A New Way to Retain State in Jetpack Compose

Jetpack Compose Runtime is introducing a new `retain` API that allows plain Kotlin objects to survive configuration changes without extending Android's ViewModel class. Unlike `remember` (survives recomposition only) and `rememberSaveable` (survives config changes via saved state), `retain` keeps arbitrary objects alive across Activity recreation with no Android lifecycle dependency. This makes state holders more reusable, framework-independent, and Kotlin Multiplatform-friendly. However, `retain` does not replace ViewModel entirely — ViewModel still provides `viewModelScope`, `SavedStateHandle`, Hilt injection, navigation integration, and lifecycle-aware cleanup. The guidance is to use `retain` for framework-independent state holders and multiplatform scenarios, and stick with ViewModel when Android-specific features are needed.

    #android#kotlin#jetpack-compose
Jul 28•4m read time•From proandroiddev.com
Post cover image
Table of contents
remember :For Local UI StaterememberSaveable : For State That Survives Configuration ChangesViewModel : For Screen-Level State ManagementGet Richa Sharma’s stories in your inbox
763 Impressions
ProAndroidDev's image
ProAndroidDev

Pand's Blog provides developers with tutorials, tips, and insights on web development, frontend tech...

441 Followers

•

1.7K Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard