Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android data storage - File vs SQLite

I am developing an application that periodically sends information to an external server. I make a local copy of the data being sent, for backup purposes.

What is the best option to store the data in terms of saving battery life? Each data submission is a serialized object (the class has 5 fields, including a date, numbers and strings) of about 5K-10K.

Any other idea?

like image 852
Guido Avatar asked Nov 26 '09 12:11

Guido


People also ask

Is SQLite faster than file system?

General Findings. SQLite is competitive with, and usually faster than, blobs stored in separate files on disk, for both reading and writing. SQLite is much faster than direct writes to disk on Windows when anti-virus protection is turned on.

Is SQLite good for Android?

Android SQLite is a very lightweight database which comes with Android OS. Android SQLite combines a clean SQL interface with a very small memory footprint and decent speed. For Android, SQLite is “baked into” the Android runtime, so every Android application can create its own SQLite databases.

Why SQLite database is a better option of storing the data?

sqlite packages offer a higher-performance alternative where source compatibility is not an issue. There is no file parsing and generating code to write and debug. Content can be accessed and updated using powerful SQL queries, greatly reducing the complexity of the application code.

Where SQLite database is stored in Android?

The Android SDK provides dedicated APIs that allow developers to use SQLite databases in their applications. The SQLite files are generally stored on the internal storage under /data/data/<packageName>/databases.


1 Answers

I have no idea in terms of battery life directly but one criteria would be which is easier to manage? Fewer operations to manage the data would mean fewer CPU cycles and in turn longer battery life.

I would say the SQLite option is easier. You can put a date column in the SQLite table which stores your data which makes removing old submissions which you don't need any more very easy - and all handled via the native SQL library. Managing a whole load of file - or worse a single file - with your own Java code would be much more work.

Additionally, you can write data the to database and just forget about it until you need to read it again. If you're storing data in files, you'll need to work out when you should be reading and writing files in terms on the Android application life cycle. If you're worried about battery you probably wouldn't want to write files more often than you should, and cache data in memory, but you'd need to make sure you didn't lose any data when your app is Paused or Destroyed. In my opinion it's much easier to use an SQLite database and not worry about any of this.

like image 70
Dave Webb Avatar answered Sep 19 '22 14:09

Dave Webb