Exercise 12 - Android Room with a View
Project name : E12 Room Word Sample
Purpose
This exercise teaches you how to use Room database and LiveData in Android Application.
Follow Codelabs Android Room with a View material and learn following things:
- Android Architecture Components
- Entity
- DAO
- Room database
- Repository
- ViewModel
- LiveData
Project name : E12 Room Word Sample
Exercise link : Android Room with a View
Note
This exercise is a little bit hard because it is old but updates frequently... and Android Studio and libraries updates frequently too. But, here are a few more hints:
Just install:
You can make a different layout and styles, you don't need to follow instructions closely. Just add a RecyclerView and Float Action Button to your layout.
If you don't get it working, you can look below build.gradle
files. Remember there might be a newer version of dependencies available.
build.gradle (project)
| // Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.1.0" apply false
id("org.jetbrains.kotlin.android") version "1.8.0" apply false
}
|
build.gradle (module)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 | import org.jetbrains.kotlin.kapt3.base.Kapt.kapt
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id ("kotlin-kapt")
}
android {
namespace = "com.example.e14roomwordsample"
compileSdk = 34
defaultConfig {
applicationId = "com.example.e14roomwordsample"
minSdk = 33
targetSdk = 33
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
dependencies {
implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.10.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
val activity_version = "1.8.0"
implementation("androidx.activity:activity-ktx:$activity_version")
val lifecycle_version = "2.6.2"
// ViewModel
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version")
// ViewModel utilities for Compose
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version")
// LiveData
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version")
// Lifecycles only (without ViewModel or LiveData)
implementation("androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version")
// Lifecycle utilities for Compose
implementation("androidx.lifecycle:lifecycle-runtime-compose:$lifecycle_version")
val room_version = "2.6.0"
implementation("androidx.room:room-ktx:$room_version")
kapt("androidx.room:room-compiler:$room_version")
}
|
Test and push
Test your application in emulator, take screenshots and commit/push your project and screenshots back to JAMKIT/GitLab. Remember move your exercise/issue ticket from Doing to In Review in Issues Board and write your learning comments to issue comments.