CPS251
Android Development
Completed Application
This is the complete application code for the RoomDatabaseDemo application. You can view the code on my GitHub page and look at the chapter11/RoomDatabaseDemo project.
How this example renders
Above is just a snippet of the code to view the full code, you need to go to my GitHub page and look at the chapter11/RoomDatabaseDemo project.
The app is running and showing two notes.
The app editing a note.
The app deletion confirmation screen.
The app after a note was deleted.
Tips for Success
- Keep your project organized by separating data, UI, and logic.
- Always add the correct dependencies for Room and Compose.
- Test your app after each major change.
- Use ViewModels to keep your UI and data in sync.
- Read error messages carefully—they often tell you exactly what's wrong!
Common Mistakes to Avoid
- Forgetting to add the
kaptplugin for Room. - Not including all your entities in the
@Databaseannotation. - Mixing UI code and data logic in the same file.
- Not updating the database version when you change the schema.
Best Practices
- Use clear, meaningful names for files and classes.
- Keep each file focused on a single job.
- Follow the MVVM (Model-View-ViewModel) pattern for clean code.
- Document your code and project structure for future reference.