facebookarchive / stetho

Stetho is a debug bridge for Android applications, enabling the powerful Chrome Developer Tools and much more.
http://facebook.github.io/stetho/
MIT License
12.66k stars 1.13k forks source link

Adding new shared preference throws type inference error #592

Open vibin opened 6 years ago

vibin commented 6 years ago

Hi, I can edit existing keys/values of SharedPreferences via Stetho, but adding a new one throws this error: "Unsupported: cannot add new key [redacted] due to lack of type inference".

maks commented 5 years ago

That kind of makes sense as SharedPreferences can be types other than Strings, but localStorage only supports String values. Perhaps for adding a new shared pref value Stetho could default to making it a String?

maks commented 5 years ago

So changing from:

if (existingValue == null) {
          throw new DOMStorageAssignmentException(
              "Unsupported: cannot add new key " + key + " due to lack of type inference");
        } else {
...

to:

if (existingValue == null) {
         existingValue = value
}
SharedPreferences.Editor editor = prefs.edit();
          try {
            assignByType(editor, key, SharedPreferencesHelper.valueFromString(value, existingValue));
...