how can i store these static data on the application?
To store the content you may use the SQLite database. The Room Persistence Library from Jetpack is a good way to start. It's an SQLite wrapper which is very easy to learn and much easy to use. This article will teach you about basic CRUD (Create, Read, Update and Delete) operation using Room.
should i use fragments to display the content?
It's up to the application requirement. One use case would be, when you have a common navigation bar, fragment would be a better option. You can find more case information on 'When to use fragments' from this answer.
@AJW
What if I already have a working SQLite database with a lot of custom
CRUD queries. And the queries use Cursors. Should I convert all of the
existing queries and replace them with new Room queries?
I haven't tried a complete migration yet, and not have too much experience with room. I tried some sample CRUD operations and it looks cool. It avoids so many boilerplate code that I used to write when using SQLiteOpenHelper
, also it supports LiveData , which is another big advantage, helps you to get database updates automatically. Altogether, Room
looks promising, and I believe it's the future. I would suggest you to do a sample project before converting all your sqlite queries to Room
. This tutorial might help you to get started also the official docs are pretty good.
can I use the SQLite queries with Room?
Yes you can. Actually, Room
needs the query to generate objects for us.
A typical SELECT
query looks like below
@Query("SELECT * FROM users")
fun loadAllUsers(): List<User>
You can find more examples from the official docs