I would like to save my push messages in SharedPreferences and then teach them in a layout as it could be.
I use firebase cloud messaging to send push messages.
I would like to save my push messages in SharedPreferences and then teach them in a layout as it could be.
I use firebase cloud messaging to send push messages.
To use SharedPreferences
you must first load the manager with:
SharedPreferences preferences = this.getSharedPreferences("TAG_APP_PREF", Context.MODE_PRIVATE);
To save a value, a manager editor is defined.
SharedPreferences.Editor editor = preferences.edit();
Now you can store data, for example a string would be made:
editor.putString("DJ","Paco Pil");
Other types of data can be stored
putBoolean, putFloat, putInt, putLong, putString
Once the data has been added to the editor, it must be saved, it is done with:
editor.apply()
To obtain data, it is done directly from the manager defined for SharedPreferences
String DJName = preferences.getString("DJ", "");
Log.d("debug, "El valor de DJ es: " + DjName);
Note that if there is no DJ
within the SharedPreferences
you will be given the default value of the second parameter, in this case ""
SharedPreferences preferences = this.getSharedPreferences("TAG_APP_PREF", Context.MODE_PRIVATE);
//Escribir datos en el gestor
SharedPreferences.Editor editor = preferences.edit();
editor.putString("DJ","Paco Pil");
editor.putString()
editor.apply();
//Leer datos del gestor
String name = preferences.getString("DJ", "");
Log.d(TAG, "El valor de DJ es: " + name);