java - Are there restrictions on what types of Strings can be saved in SharedPreferences? -
A small, Siriyljbl object to me that I continue between sessions outside the context of any activity. My first thought was to write it in a shared file, but unfortunately the class does not support reading or writing a normal serializable. But it supports the string. So my next thought: a Siriyljbl an array of just bytes, and string 2-byte is an array of characters ... Why not broken into two bytes my byte at a time, change the byte of each pair in a Four, and construct a string outside those characters (and then do reverse to read it back)? I tried it and it works fine, most of the time but at one time, fails to serialize the object for some time. After looking into it for a while, I realized that there is something wrong with writing before the failed shots. In particular, shows the logcat being thrown while writing these exceptions (and caught) within the framework of code:
java.io.IOException: java.nio.charset.CoderResult [distorted and wrong input length error com.android.internal with input 1] com.android.internal.util.FastXmlSerializer.flush (FastXmlSerializer.java:225) com.android.internal.util.FastXmlSerializer.endDocument (FastXmlSerializer. Java: 183) but on. android.app.SharedPreferencesImpl on util.XmlUtils.writeMapXml (XmlUtils.java:186) on android.app.SharedPreferencesImpl.writeToFile (SharedPreferencesImpl.java:596) in android.app.SharedPreferencesImpl.access $ 800 (SharedPreferencesImpl.java:52) $ 2 .run (SharedPreferencesImpl.java:511) android.app.SharedPreferencesImpl.enqueueDiskWrite (SharedPreferencesImpl.java:532) android.app.SharedPreferencesImpl $ EditorImpl on android.app.SharedPreferencesImpl.access $ 100 (SharedPreferencesImpl.java:52) MIT (shared context implication .J.Y. 454) on .com;
This exception never preaches for my code; As far as it can tell, everything works well.
After reading four documents, my best estimate is that I sometimes coincide with those four whose numeric value is said in the "high surrogate" category, the character is "less One is not followed in the "surrogacy" category, and as a result, my string is simply plain invalid (or is able to mislead at least shared references / XML codes).
Naturally I would rather use regular file I / O or Base64 encoding instead, but I want to understand what is happening if possible.
Comments
Post a Comment