I am building a program that randomly generates multidimensional list arrays of the type :
ArrayList(ArrayList(ArrayList(String)));
My challenge is to find a way to save and restore these array lists once they have been (randomly) generated. I believe one solution is to convert them to a string and restore the array from that string although I can't seem to find a way to do so (I tried Json and deepToString). Please let me know if anyone has an idea. Thanks.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
Gson gson = new Gson();
if (savedInstanceState == null) {
//GEREATE MAP
GenMap();
jsonmaps = gson.toJson(maps);
} else {
maps = gson.fromJson(jsonmaps, new TypeToken<ArrayList<ArrayList<ArrayList<String>>>>() {
}.getType());
}
//LAYOUT MAP
MapLayout();
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
jsonmaps = savedInstanceState.getString("Sjsonmaps");
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putString("Sjsonmaps", jsonmaps);
}