Share
Explore

App Android Room Lab Instructions

Project FILE:

I will call my App AndroidRoom2 -> Align all files with this name.
remember that we must not use JetPack Compose at all.
For your app AndroidRoom2, where we will demonstrate CRUD operations using the Android Room Persistence Library, an "Empty Activity" would be the best starting point.
This template provides a clean slate, allowing you to design your app from the ground up without any additional UI elements or configurations that you don't need.
Once you select "Empty Activity" and configure your app's name and save location, you can proceed to set up your activity and the associated XML layout file. This will give you the flexibility to create a user interface that includes a text box, a button, and other elements necessary for your shopping list application, without any unnecessary extras.

remember that we had incorrectly made the Android KOTLIN ROOM Database grocery list app to use JetPack compose and we will not be being JetPack compose at all ever. Now we must fix MainActivity.kt to remove all references to Composables and JetPack compose which we did. Now fix this error message in MainActivity.kt: e: file:///C:/AndroidStudioProjects/AndroidRoom2/app/src/main/java/com/example/androidroom2/MainActivity.kt:8:26 Unresolved reference: layout Here is my current MainActivity.kt which must be fixed: import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import com.example.androidroom2.R // Import the R class
class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Use the R class to reference the layout file } } The error is at this line: setContentView(R.layout.activity_main) // Use the R class to reference the layout file


this is what you make before our session was interrupted: our need is make a simple Android Kotlin app using GRADLE DSL and avoiding any use of JetPack Compose. I want an app with a screen that presents a text box which the user enters a grocery item into and that text is stored in an Android KOTLIN ROOM database. Every time the user enters a grocery item into the text field, that item is persisted into the Room database and displayed on the screen. We will make ample use of LOGGING out to logcat so students can see the results of their code running.

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidroom2">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Other activities or components -->
</application>

</manifest>

gradle project level
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.jetbrainsKotlinAndroid) apply false
}



gradle module level
plugins {
id("com.android.application")
kotlin("android")
kotlin("kapt")
}

android {
namespace = "com.example.androidroom2"
compileSdk = 34

defaultConfig {
applicationId = "com.example.androidroom2"
minSdk = 33
targetSdk = 34
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {
implementation("androidx.core:core-ktx:1.7.0")
implementation("androidx.appcompat:appcompat:1.4.1")

// Room components
implementation("androidx.room:room-runtime:2.4.2")
kapt("androidx.room:room-compiler:2.4.2")
// Kotlin Extensions and Coroutines support for Room
implementation("androidx.room:room-ktx:2.4.2")

// Kotlin coroutines
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0")

// Testing libraries
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
}

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.