Search code examples
androiddatabaseperformancepojomemory-efficient

More efficient in Android app? Database or Objects


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.


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.