Question

I have 30 objects, each instance consisting of 7 string fields and a small bitmap. These objects will be destroyed and recreated daily. In my android app, would it be more efficient to write and read this data from a db? or to simply create a new class and create the 30 instances and store them in an array? Memory efficient/performance/etc.

Thank you for your time.

Was it helpful?

Solution

If you do not want to write boilerplate code for database you can save your objects in JSON or XML format as files.

You got two ways:

  1. Store in filesystem using serialization to store and deserialization to read
  2. Store in JSON or XML natively and write converter between your class and needed data format

Database is good solution, because SQLite in Android is real fast and so on. But if you will want to change structure of table you will have to write ALTER TABLE queries in onUpdate() method of SQLiteOpenHelper and other troubles.

So I would recommend to use XML or JSON to store data.

Upd

Also, you can mark your custom data class as serializable, store values in ArrayList or other structure and serialize it to store, then deserialize to read.

OTHER TIPS

Write the items to a database because they need to be persistent, if only for 24 hours.

You should store the image files in your Internal Storage sandbox and reference them by filename in the database because it is usually inefficient to store even the smallest Bitmap blobs in the database.

For a limited number of object I think you are batter with Object representation and storing them in an ArrayList. DB design for a large number of entries.

But if the data needs to be saved for all day you are risking in loosing it by a GC if you leave it in memory, in that case you have no option but to store it in the DB.

where are you getting this data from?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top