Why to use sqlite Database in Android? Why to use sqlite Database in Android? android android

Why to use sqlite Database in Android?


It is good to use database in your case.

Pros:

  • If your application gets closed the in memory data will be lost, but after that you will be able to restore the state from the database if you have one
  • Especially for the case of complex calculations it is good to store the result once in the database and not recalculate it multiple times on demand
  • The database will untie your UI from the internet connection and thus you will be able to display results even if there is not internet connection
  • Using database you will be able to fetch the updated data from a background service, without impacting your UI
  • Organizing your data in database usually makes it a lot easier to manage all the application data.

Cons:

  • Adding database will require a bit of additional effort on your side

As you can see my list proves you SHOULD use database in your case. Maybe I am biased, but at least I provide you with things to consider.


It's really a design decision, SQLite offers a very robust way to organize and persist your data, you're only other options are to write to a file, or to save in SharedPrefs, both methods become a lot harder to manage once the size of your data begins to grow, as you must manually keep a list of objects and manage their names etc etc. 40 x 40 table data is large enough to justify using SQLite, even if you are dropping and recreating the table every 12 hours.

You might want to consider using an ORM library to make fetching and saving data from the DB simpler, ORMLite is good and compatible with Android

http://ormlite.com/


If your application relies heavily on an internet connection you don't need to buffer information in the database. However if you want to use the app where you have bad or no signal you might want to used cached values from the sqlite database.With slow internet connection your application may be unresponsive so caching may be a good idea - but it doesn't necessarily be in the sqlite database. You should use the sqlite database for data that is required by the device frequently and that is irrelevant to your server component.If the data is updated frequently but only while the application runs you might want to cache in the devices memory. I assume your app is not running all the time within the 12 hours but is called regularly instead to check something.