Logic loaded in memory vs in the database in Android

Go To StackoverFlow.com

3

I have a question about what is the best approach for an generic Android app for showing static and dynamic info (with persistent info):

Lets imagine an simple app with some persistent collections and some relations between those items: for example an app that shows a list of pilots a list of car pilots and a list of favorite pilots for the user. The user can manually refresh a pilot or a car profile and the new data must be saved persistently

A) Use mechanisms for loading from the database the corresponding classes and Lists (for example) into logic classes, accessing them with managers (PilotManager for example) and reflecting the changes that affect persistently to those objects and, in parallel, reflect the changes in the data base. Those objects stay in memory while the app is running.

B) Work directly with the database engine, recovering from there in each moment the elements needed for display or work. For example for listing the pilots query the database and use an CursorAdapter for list them. If a pilot is selected query the database for his car and show its values. Any change is directly saved to the database and refreshed from there.

I generally use the method A) because is very fast granting the user a high responsivity in the interaction because (except in the first load) no database accesses are required. But a friend told me that B) is better because you use less memory and you can seize the database engine for handle complex filters of searches.

Are both approaches valid? Someone is wrong? Thanks!

2012-04-05 20:31
by Caroline


1

Solution A is good if you do something like a game, when you need a good performance and speed.

But solution B is good for usual applications, where user goes from one activity to another. Also solution B is good for memory saving (if you have a lot of objects you may get a memory error in solution A)

2012-04-05 20:42
by Alex Klimashevsky
Ads