The FULL Beginner Guide for Room in Android | Local Database Tutorial for Android

Philipp Lackner · 210K views · 2023 · 47:19

Open on YouTube

Software (other)Web developmenttutorial

Why Stack Overflow recommends it

Stack Overflow users link it as the Room tutorial they are following, or as a reference for the ViewModel and event pattern, when they hit errors in the code it builds.

Recommended by 0 people across 0 different months, 2024 to 2024.

What it is

A 47-minute beginner tutorial by Android developer Philipp Lackner on using Room, Android's local database library, with Kotlin and Jetpack Compose. It builds a contacts app with entities, a DAO, a ViewModel with events and state, and a Compose UI with an add-contact dialog.

What people said

Cites Prakhar_Pathak · 2024-02 · Stack Overflow · on “How to replace multiple lambda () -> Unit in a composable in Jetpack compose android”

You may use viewModel and event To manage the events that is happening in a particular screen. I had learned about this process in recent times only by seeing the video of this person on Youtube [this video] . He had made a different app but used the same approach. You may also take reference from him for better understanding. My approach is like this -> ChatMessageState.kt - data class ChatMessageState( val authorName: String = "", val authorImageUrl:String = "", val dataSent:String = "", val messages : List<String> = listOf("something"), val likeCounts: List<Int> = listOf(1,3) ) ChatMessageEvent.kt-> sealed interface ChatMessageEvent { data class SetAuthorName(val authorName: String): ChatMessa

Cites Siddhant Samarth · 2024-06 · Stack Overflow · on “Why is information not being retrieved from the Room Database when returned as a Flow?”

Everything was working fine initially, but later I added a table to the database. I have wiped all data and started fresh, so I don't think its a migration issue. The initial tables are working fine as expected. For the new table when I run the query through app inspector then it works fine within the app inspector. However when the query (specified in the dao) is called through the ViewModel, it returns an empty list. within the DAO: @Query("SELECT * FROM PropTable") fun readPropReport(): Flow<List<PropReport>> within the viewModel: val _propReportsU = dao.readPropReport().stateIn(viewModelScope, SharingStarted.WhileSubscribed(500), emptyList()) Log.i("Prop Function", "Prop Reports 'U': ${_

Cites genespos · 2024-11 · Stack Overflow · on “Unable to get correct import for AlertDialog (Or deprecated import?)”

I'm following a Room tutorial [this video] for Kotlin and (at about 40 minutes) I get the following error: [LINK] Below is my code (I checked it and it seems exactly how shown in the video) @Composable fun AddContactDialog( state: ContactState, onEvent: (ContactEvent) -> Unit, modifier: Modifier = Modifier ){ AlertDialog( modifier = modifier, onDismissRequest = { onEvent(ContactEvent.HideDialog) }, title = { Text(text = "Add contact") }, text = { Column( verticalArrangement = Arrangement.spacedBy(8.dp) ){ TextField( value = state.firstName, onValueChange = { onEvent(ContactEvent.SetFirstName(it)) }, placeholder = { Text(text = "First Name") } ) TextField( value = state.lastName, onValueChange = {

Cites genespos · 2024-11 · Stack Overflow · on “Unable to get import to fix "onClick" unrecognized giving error”

I'm new to Kotlin and I'm following a Room tutorial [this video] but (at about 32 minutes) I get an error that I wasn't able to fix: [LINK] This is my code: @Composable fun ContactScreen( state: ContactState, onEvent: (ContactEvent) -> Unit ){ Scaffold( floatingActionButton = { FloatingActionButton(onClick ={ onEvent(ContactEvent.ShowDialog) }){ Icon(imageVector = Icons.Default.Add, contentDescription = "Add contact") } } ){padding -> LazyColumn ( contentPadding = padding, modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(16.dp) ){ } } } these are my imports: import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.fillMaxSize imp