Search code examples
androidsqliteandroid-studiomvvmandroid-sqlite

MVVM vs SQLiteOpenHelper for android database. Having a bit of a confusion


I have been looking into how databases work in android and have been learning MVVM (Model–View–ViewModel). But I am seeing a lot of examples of SQliteOpenHelper being used here rather then MVVM.

After learning MVVM, I am starting to get confused about SQLiteOpenHelper(Though I have not learned anything about it). I do understand that MVVM is the standard and that MVVM has SQLite in it, but when I look at examples of SQLite in stack overflow, I am seeing cursors and stuff, which I do not know.

For the application that I am planning to make is using MVVM or SQLiteOpenHelper better? The data that I need to store in column is date, Something, something, something. So just four columns of data. I will be storing data locally.

I do like MVVM though, but does it go well for my purpose?


Solution

  • MVVM is a software architectural pattern and not a particular implementation. The database itself should reside within the Model portion of your code. Here SQLiteOpenHelper comes into play. It's the standard to access databases in Android. Therefore any actual implementation you choose relies on it as well.

    To get started with databases you should consider using Room as it's an abstraction of the database, providing DAOs and Entities. No need to implement an SQLiteOpenHelper or handle cursors.