Try to read key with new data type, in case of ClassCastException
exception delete "old" key, and create new key with same name but new type. Something like this:
SharedPreferences prefs;
String key = "key";
prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (prefs.contains(key)) {
// key exists, so tetermine it's type
try {
prefs.edit().get<old_type_name>(key, <default_old_type_value>);
} catch (Exceprtion e) {
if (e instanceOf ClassCastException) {
prefs.edit().remove(key).apply();
}
}
}
// we are here if no key exists or key removed
prefs.edit().put<new_type_name>(key, <new_type_value>).apply();
and if needed do check if (prefs.contains(key)) ...
only once on first app start.