androidx.lifecycle:lifecycle-viewmodel
Official Description: Android Lifecycle ViewModel
CommonsWare’s Notes
As the name suggests, this artifact contains ViewModel
, the Jetpack solution
for retaining data across configuration changes. Despite its name, ViewModel
is not strictly tied to MVVM or other GUI architectures that use
“viewmodel” as a term.
This artifact also contains ViewModelProvider
and ViewModelStore
, ways for you
to obtain ViewModel
instances. It also contains AndroidViewModel
,
a ViewModel
that has a Context
that you can use for all those places
where you need a Context
.
As with many facet of the Jetpack, ViewModel
was introduced before the
migration to androidx
Java packages. If you see references to
android.arch.lifecycle.ViewModel
, the AndroidX equivalent has a near-identical
API and fills the same role.
Documentation
Knowledge
- Passing Data Between Fragments on Android Using ViewModel (2019-07-30)
- Using ViewModel with RoomDatabase (2019-03-15)
Samples
- Elements of Jetpack Basic ViewModel Example (Java)
- Elements of Jetpack Basic ViewModel Example (Kotlin)
Versions
- Latest Stable: 2.3.0
- Latest Release Candidate: 2.3.0-rc01
- Latest Beta: 2.3.0-beta01
- Latest Alpha: 2.3.0-alpha07
- 2.3.0
- 2.3.0-rc01
- 2.3.0-beta01
- 2.3.0-alpha07
- 2.3.0-alpha06
- 2.3.0-alpha05
- 2.3.0-alpha04
- 2.3.0-alpha03
- 2.3.0-alpha02
- 2.3.0-alpha01
- 2.2.0
- 2.2.0-rc03
- 2.2.0-rc02
- 2.2.0-rc01
- 2.2.0-beta01
- 2.2.0-alpha05
- 2.2.0-alpha04
- 2.2.0-alpha03
- 2.2.0-alpha02
- 2.2.0-alpha01
- 2.1.0
- 2.1.0-rc01
- 2.1.0-beta01
- 2.1.0-alpha04
- 2.1.0-alpha03
- 2.1.0-alpha02
- 2.1.0-alpha01
- 2.0.0
- 2.0.0-rc01
- 2.0.0-beta01
- 2.0.0-alpha1