File or Database? - Best Practice to save Objects on Android-Device

android, database, file, gson, json

Solution

It really depends on your use case.

If your application data doesn't change a lot (think a conference app that is used once or twice a year), then you can use a ContentProvider + CursorAdapters which will make your life easier.

If your application data changes a lot (think Gmail, where as much as hundreds of email can pop-up every day, or a news feed, or a social networking app like Google+), then a database could probably make your life worse. You should use in this case a 3rd party caching system, like Google Volley or RoboSpice, etc. which handles all the caching of JSON objects for you and all the concurrency problems that appear, etc.

Problem

I'm building an android application in java where I define some Objects like "user" or "playlist" etc.. How to save these self-defined objects on the device for later access? ``` Gson gson = new Gson(); String json = gson.toJson(user); ``` I can parse the objects via GSON to a JSONObject or a JSONArray. Now I have two options to save the strings: In a Database or a File. I know how to use the android database-classes and the filewriter/reader classes, but what is the best practice with regards to performance, accessibility and especially to simplicity?

Original source

Related problems