Codi GSON Object Serialization
per Jordi Farrero
—
darrera modificació
2020-03-25T14:54:39+01:00
// CONVERTEIX EL OBJECT a JSON format
Gson gson = new Gson();
String load_data = gson.toJson(OBJECT );
SharedPreferences settings = getSharedPreferences("GameAppSavedData", MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
// GUARDAR OBJECTE
String saved_data = gson.toJson(OBJECT );
// SAVE DATA TO SHAREDPREFERENCES
editor.putString("Full_Saved_Data", saved_data);
editor.putBoolean("isFirstRun_Flag",false);
editor.commit();
// RECUPERAR OBJECTE
load_data = settings.getString("Full_Saved_Data", "");
OBJECT = gson.fromJson(load_data, OBJECT .class);