You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learning-paths/smartphones-and-mobile/build-android-selfie-app-using-mediapipe-multimodality/5-view-model-setup.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,21 +8,21 @@ layout: learningpathall
8
8
9
9
## ViewModel
10
10
11
-
The `ViewModel` class is a [business logic or screen level state holder](https://developer.android.com/topic/architecture/ui-layer/stateholders). It exposes state to the UI and encapsulates related business logic.
11
+
The `ViewModel` class is a business logic or screen level state holder, as explained in [ViewModel overview](https://developer.android.com/topic/architecture/ui-layer/stateholders) on the Android Developer website. It exposes state to the UI and encapsulates related business logic.
12
12
13
-
The main advantage of using `ViewModel` is that it caches state and persists it through configuration changes. This means that the UI does not have to fetch data again when navigating between activities, or following configuration changes, such as screen rotation.
13
+
The main advantage of using the `ViewModel` class is that it caches state and persists it through configuration changes. This means that the UI does not have to fetch data again when navigating between activities, or following configuration changes, such as screen rotation.
14
14
15
-
## Introduce Jetpack Lifecycle dependency
15
+
## Add Android Jetpack Lifecycle libraries
16
16
17
-
You can now bring in the Jetpack Lifecycle libraries.
17
+
You can now add Jetpack Lifecycle libraries to your app.
18
18
19
-
1. Navigate to `libs.versions.toml` and append the following line to the end of `[versions]` section. This defines the version of the Jetpack Lifecycle libraries that you will be using.
19
+
1. Navigate to `libs.versions.toml` and append the following line to the end of the `[versions]` section. This defines the version of the Jetpack Lifecycle libraries that you will be using.
20
20
21
21
```toml
22
22
lifecycle = "2.8.7"
23
23
```
24
24
25
-
2. Insert the following line to `[libraries]` section, ideally between `androidx-appcompat` and `material`. This declares the Jetpack Lifecycle ViewModel Kotlin extension:
25
+
2. Insert the following line to the `[libraries]` section, ideally between `androidx-appcompat` and `material`. This declares the Jetpack Lifecycle ViewModel Kotlin extension:
26
26
27
27
```toml
28
28
androidx-lifecycle-viewmodel = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx", version.ref = "lifecycle" }
@@ -102,7 +102,7 @@ You might notice that success and failure messages are logged with different API
102
102
{{% /notice %}}
103
103
104
104
2. Bind `MainViewModel` to `MainActivity` by inserting the following line into `MainActivity.kt`, above the `onCreate` method.
105
-
Don't forget to import the `viewModels`[extension function](https://kotlinlang.org/docs/extensions.html#extension-functions) through `import androidx.activity.viewModels`.
105
+
Do not forget to import the `viewModels`[extension function](https://kotlinlang.org/docs/extensions.html#extension-functions) through `import androidx.activity.viewModels`.
106
106
107
107
```kotlin
108
108
privateval viewModel:MainViewModel by viewModels()
0 commit comments