It is convenient to use SharedPreferences to store some common settings. However, we know that SharedPreferences can only store some simple types. How can we use SharedPreferences to store some complex objects? The following uses map as an example to see how SharedPreferences stores complex objects. If you want to use SharedPreferences to access complex data types, you need to encode the data. Data is usually converted to Base64 encoding, And the converted data is stored as strings. Storage: [java] // converts a map to byte [] ByteArrayOutputStream toByte = new ByteArrayOutputStream (); ObjectOutputStream oos = new ObjectOutputStream (toByte); oos. writeObject (map); // encode byte [] In Base64 String payCityMapBase64 = new String (Base64Coder. encode (toByte. toByteArray (); // stores the editor. putString (KEY_CITY, payCityMapBase64); editor. commit (); // convert map to byte [] ByteArrayOutputStream toByte = new ByteArrayOutputStream (); ObjectOutputStream oos = new ObjectOutputStream (toByte); oos. writeObject (map); // encode byte [] In Base64 String payCityMapBase64 = new String (Base64Coder. encode (toByte. toByteArray (); // stores the editor. putString (KEY_CITY, payCityMapBase64); editor. commit (); The following is read: [java] byte [] base64Bytes = Base64Coder. decode (prefer. getString (KEY_CITY, null); ByteArrayInputStream bais = new ByteArrayInputStream (base64Bytes); ObjectInputStream ois = new ObjectInputStream (bais); map = (Map) ois. readObject (); boolean B = (Boolean) map. get (cityId); byte [] base64Bytes = Base64Coder. decode (prefer. getString (KEY_CITY, null); ByteArrayInputStream bais = new ByteArrayInputStream (base64Bytes); ObjectInputStream ois = new ObjectInputStream (bais); map = (Map) ois. readObject (); boolean B = (Boolean) map. get (cityId );