I have the following data structure for a movies SQLite db (i will keep it simple , the real tables have more fields):
- genre – (id , name)
- movie – (id , genreId , name , year)
- scenes – (id , movieId , name)
for example:
- genre – (7 , thriller)
- movie – (250 , 7 , The Sixth Sense , 1999)
- scenes – (15 , 250 , I see dead people)
I have the data stored in an SQLite db on my Android app.
I have a data manager class that I use to retrive relevant data.
I need to be able to do the following:
- get ALL genres
- get ALL movies per genre id (+ the abbilty to sort according to different fields)
- get a SPECIFIC movie item according to movie id
- get ALL scenes according to movie id
- …
I would like to know, performance-wize, what is the better way to approach this data:
- perform a SQLite query every time I need to get data.
- after getting data once from th db, store it in an array list and thus keeping it in memory, for example – ArrayList of genres, where a Genre object holds an array list of Movie objects…
- same as option 2 but with hash maps. in that case – when looping over the map, is there a way to control the order of the objects?
- any other option that comes to mind?
Usually, you retrieve data from database and use CursorAdapter to represent data in a ListView. So, I guess this is the most effective way. If you have different activities for your tables, until activities are destroyed they will store your data in memory.