我需要一些幫助才能從我的自定義首選項中獲取所有sharedPreferences(鍵值&值),但這是爲了使它們最初插入到首選項文件中。我目前有下面的代碼但問題是因爲getAll()返回一個映射順序的變化。需要獲取所有sharedPreferences但按正確的插入順序
public List<String> getPrefValues(String pref, Context context) {
Map<String, ?> allEntries = context.getSharedPreferences(pref,
Context.MODE_PRIVATE).getAll();
List<String> command = new ArrayList<String>();
for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
command.add(new StringBuilder(entry.getKey())
.append(":")
.append(entry.getValue()).toString());
}
if (command.isEmpty()) {
return null;
} else {
return command;
}
}