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();
精彩评论