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?
Shared Preferences is the easiest to use, especially if you want to store discrete primitive data types. However, internal and external storage is best for storing files such as music, videos, and documents, while SQLite wins if you need to perform fast searches and queries on your data.
PostgreSQL. A unique relational database, PostgreSQL is the best database for Android and iOS apps. Developers can customize this database as they want; that's why it's the most preferred mobile app database.
You can use application preferences to store data as shown here (if the data is small enough). SharedPreferences gameSettings = getSharedPreferences("MyGamePreferences", MODE_PRIVATE); SharedPreferences. Editor prefEditor = gameSettings. edit(); prefEditor.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With