I tried this so far: Why do I get an UnsupportedOperationException when trying to remove an element from a List? Well, The exception doesn't appear anymore but.. the app doesn't reply anymore.. I store 2 lists in my shared preferences with this method:
public void storeList(List<?> lList, String storeString) {
String s = new Gson().toJson(lList, new TypeToken<List<?>>() {
}.getType());
editPrefsLists.putString(storeString, s).apply();
editPrefsLists.commit();
}
Well, before I get the UnsupportedOperationException I tried to read the list with this method:
public <T> List<T> stringToArray(String storedString, Class<T[]> clazz) {
T[] arr = new Gson().fromJson(sharedPrefsLists.getString(storedString, null), clazz);
if (arr != null) {
return Arrays.asList(arr); //or return Arrays.asList(new Gson().fromJson(s, clazz)); for a one-liner
} else {
return null;
}
}
After the Exception I tried it with a LinkedList and make this:
public <T> List<T> stringToArray(String storedString, Class<T[]> clazz) {
T[] arr = new Gson().fromJson(sharedPrefsLists.getString(storedString, null), clazz);
if (arr != null) {
LinkedList<T> newList = new LinkedList<>(Arrays.asList(arr));
return newList; //or return Arrays.asList(new Gson().fromJson(s, clazz)); for a one-liner
} else {
return null;
}
}
Now, the app doesn't reply anymore and close itself. How can I solve this problem?