Logic loaded into memory and database on Android

I have a question about what is the best approach for a generic Android app to show static and dynamic information (with constant information):

Let's imagine a simple application with some persistent collections and some relationship between these elements: for example, an application that shows a list of drivers of a list of car drivers and a list of favorite drivers for the user. The user can manually update the pilot or car profile and the new data must be persistently saved.

A) Use the mechanisms of loading the corresponding classes and lists from the database (for example) into logical classes, referring to them with managers (for example, PilotManager ) and reflecting changes that persistently affect these objects and, in parallel, reflect changes in the database. These objects remain in memory while the application is running.

B) Work directly with the database engine, restoring from there at any time the elements necessary for display or work. For example, to list pilots, query the database and use the CursorAdapter to list them. If a pilot is selected, query the database for your vehicle and show its values. Any change is directly saved to the database and updated from there.

I usually use method A) because it very quickly gives the user a high sensitivity to interaction because (other than the first load) no database access is required. But a friend told me that B) is better because you use less memory and you can hijack the database engine to handle complex lookup filters.

Are both approaches available? Someone is wrong? Thank!

+3


source to share


1 answer


Solution A is useful if you are doing something like a game where you need good performance and speed.



But solution B is suitable for normal applications where the user navigates from one activity to another. Also solution B is useful for saving memory (if you have a lot of objects you might get a memory error in solution A)

+1


source







All Articles