Android - Use a database?

0

I'm developing an application for Android , what my application does is just show ListViews with information (Approximately 100 items). This information will always be the same and will never change. What I want to know is: What is the best way to store this information? To have everything in a database? Or Type all this information in Java code? In the case of the first option, how do I configure SQLite so that the application installs with the information already loaded?

    
asked by Joseph Alberto Morthimer Leon 14.11.2016 в 21:11
source

3 answers

2

I recommend you use a JSON file and save it in the resources of your app, this way it will be much easier to implement the solution and modify the list in case you need it. To consume the JSON I recommend using Gson which allows you to convert java objects in your Json representation and vice versa almost automatically.

    
answered by 15.11.2016 / 18:05
source
1

I recommend that you use a SQlite database in which to install the app directly make the inserts you want with the data you want and then work with it.

Here is a guide to make the SQLite database and all that it entails: Guide

I also recommend that you use the RecyclerView instead of the ListView, it is a bit more difficult to implement but there are thousands of tutorials online and it is not much harder to do either.

    
answered by 15.11.2016 в 18:31
1

You can store some values for your app using the Android SharedPreferences, example:

SharedPreferences preferences;
SharedPreferences.Editor editor_pref;

...
//INiciar el preferences
PreferenceManager.getDefaultSharedPreferences(this); //Necesita un Context

//Iniciar el editor (solo para almacenar)
editor_pref = preferences.edit();

//Guardar data
editor_pref.putString("tu_key", "tu valor");
editor_pref.putInt("tu_otra_key", 100);
...
//Salvar los cambios
editor_pref.commit();

//Recuperar data
preferences.getString("tu_key", "Puedes enviar un valor por defecto");
preferences.getInt("tu_otra_key", 0);

For example, to know if I should remove some assets in my app I use this:

if (preferences.getBoolean("remove_assets", true)) {
   removeAssets();
}

It's a simple way to store some data, especially to control the behavior of the app!

I leave the official doc: Android Documentation

    
answered by 30.08.2017 в 03:46