开发者

Android store array in preferences

开发者 https://www.devze.com 2023-01-07 21:04 出处:网络
I know only primitives can be stored in the android preferences, but do arrays count? Can I store an array of, say, Strings or booleans开发者_如何学Go in an android preference?Only if you turn the arr

I know only primitives can be stored in the android preferences, but do arrays count? Can I store an array of, say, Strings or booleans开发者_如何学Go in an android preference?


Only if you turn the array into a string.


 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 will get and populate the array and below 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();
0

精彩评论

暂无评论...
验证码 换一张
取 消