Android store array in settings

I know that only primitives can be stored in android settings, but do arrays count? Can I store an array of, say, strings or logical elements in android preference?

+3
source share
2 answers

Only if you include an array in a string.

+1
source
 SharedPreferences settings = getSharedPreferences(PREFS_NAME,0);
    for(int n =0;n<LevelMenu.buttonState.length;n++){ 
        LevelMenu.buttonState[n]= (byte) settings.getInt("levelsave"+n,0);
    }

Above it will receive and populate the array, and below it will depopulate and save.

SharedPreferences settings = getSharedPreferences(PREFS_NAME,0);
   SharedPreferences.Editor editor = settings.edit();
   for(int n =0;n<LevelMenu.buttonState.length;n++){
        editor.putInt("levelsave"+n,LevelMenu.buttonState[n]);
   }
editor.commit();
+2
source

Source: https://habr.com/ru/post/1754683/


All Articles