If you want the array data (such as boolean[], int[], etc.) to sharedpreferences, we can first organize the array data into JSON data to sharedpreferences, and then parse the JSON data when reading is OK.
For example, I want to save boolean[] Array data:
public static void Saveapkenalblearray (Context context,boolean[] booleanarray) {Sharedpreferences prefs = Context.getsharedpreferences (Apk_enable_array, context.mode_private); Jsonarray Jsonarray = new Jsonarray (); for (Boolean B:booleanarray) {jsonarray.put (b);} Sharedpreferences.editor Editor = Prefs.edit (); Editor.putstring (apk_enable_array,jsonarray.tostring ()); Editor.commit ();}
Read data:
public static boolean[] Getapkenablearray (Context context,int arraylength) {Sharedpreferences prefs = Context.getsharedpreferences (Apk_enable_array, context.mode_private); boolean[] Resarray=new boolean[arrayLength]; Arrays.fill (Resarray, true); try { Jsonarray Jsonarray = new Jsonarray (prefs.getstring (Apk_enable_array, "[]")); for (int i = 0; i < jsonarray.length (); i++) { Resarray[i] = Jsonarray.getboolean (i);} } catch (Exception e) { C4/>e.printstacktrace ();} return Resarray;}
When you save some complex array of objects, you can use Gson to handle the conversion of JSON and object to each other.
"Android" stores array data to Sharedpreferences