Video coming soonBeginner 45 min Kotlin Full project
Notes App in Jetpack Compose with Room Database (2026)
Build a beautiful notes app from scratch with Jetpack Compose and Room: colourful cards, live search, pin to top, a colour picker and delete with Undo. The modern way to save data on Android, step by step.
The video is on its way. The full code and every step are ready below.
In Android Studio choose New Project → Empty Activity (the Compose one), with Minimum SDK API 24. To copy the code unchanged, use the package name com.example.notes.
2. Add Room, Navigation and KSP
In gradle/libs.versions.toml, add the versions, libraries and the KSP plugin shown in Required setup (Room 2.8.5, Navigation 2.10.2, Lifecycle 2.11.0, KSP 2.3.12). Then in app/build.gradle.kts:
And in the project-level build.gradle.kts, add alias(libs.plugins.ksp) apply false to plugins. Press Sync Now. KSP is the tool that generates Room's database code for you.
3. Describe a note
Note is a Kotlin data class with @Entity. Room creates a notes table with a column for each property: id, title, content, color, pinned and updatedAt. @PrimaryKey(autoGenerate = true) numbers notes for you.
4. Write the DAO
NoteDao is an interface; Room writes the code.
observe(query) returns a Flow<List<Note>> with pinned notes first. Whenever the table changes, the Flow sends the new list.
@Upsert inserts a new note or updates an existing one.
@Delete removes a note.
5. Create the database
NoteDatabase extends RoomDatabase and lists Note as its entity. A companion object makes sure the app opens it only once.
6. Add the ViewModel
NotesViewModel holds the search text in a MutableStateFlow. flatMapLatest re-runs the database search whenever the text changes, and stateIn turns it into a StateFlow the screen can read. Saves and deletes run in viewModelScope, off the main thread.
7. Set the colours
Theme.kt defines six pastel note colours and Material 3 light and dark themes. Each note stores a colour index, so you can change the palette later.
8. Build the notes list
NotesScreen shows a big "My Notes" header, a rounded search box, and a LazyVerticalStaggeredGrid, which lays cards out like Pinterest so short and long notes fit together. Each card uses its note's colour, and the pin icon toggles pinning.
9. Build the editor
EditNoteScreen paints the whole screen in the note's colour. Two borderless TextFields hold the title and text, and rememberSaveable keeps what you typed if the phone rotates. A row of colour circles changes the note's colour.
10. Save when leaving
The back arrow, the tick and the system Back gesture (BackHandler) all save. Completely empty notes aren't saved.
11. Connect the screens
In MainActivity, a NavHost has two routes: notes and edit/{id}, where 0 means a new note. collectAsStateWithLifecycle reads the ViewModel's flows safely.
12. Delete with Undo
Deleting goes back to the list and shows a snackbar. Tapping Undo saves the note again.
Run it
Add a few notes in different colours, pin one, search for a word, then delete a note and tap Undo. Rotate the phone while editing; nothing is lost.
If something goes wrong
"Cannot find implementation for NoteDatabase": KSP isn't running. Check ksp(libs.androidx.room.compiler) and the KSP plugin.
The list doesn't update: make sure the DAO query returns a Flow.
Editor hidden behind the keyboard: keep adjustResize in the manifest and imePadding() on the editor column.
Files affected
Check what to add and what to replace before copying code.