1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
// HashMap 저장
public void SaveUrlMap(Context context, HashMap<String, String> hashMapData) {
SharedPreferences mmPref = context.getSharedPreferences("pref", Context.MODE_PRIVATE);
if (mmPref != null) {
JSONObject jsonObject = new JSONObject(hashMapData);
String jsonString = jsonObject.toString();
SharedPreferences.Editor editor = mmPref.edit();
editor.remove("hashMapName").commit();
editor.putString("hashMapName", jsonString);
editor.commit();
}
}
// HashMap 불러오기
public HashMap<String, String> LoadUrlMap(Context context) {
HashMap<String, String> outputMap = new HashMap<String, String>();
SharedPreferences mmPref = context.getSharedPreferences("pref", Context.MODE_PRIVATE);
try {
if (mmPref != null) {
String jsonString = mmPref.getString("hashMapName", (new JSONObject()).toString());
JSONObject jsonObject = new JSONObject(jsonString);
Iterator<String> keysItr = jsonObject.keys();
while (keysItr.hasNext()) {
String key = keysItr.next();
String value = (String) jsonObject.get(key);
outputMap.put(key, value);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return outputMap;
}
|
cs |
'개발 > Android' 카테고리의 다른 글
[Android] app restart 앱 재실행 (0) | 2021.03.05 |
---|---|
[Android] list 아래 여백 추가 (0) | 2021.01.19 |
[Android] 앱 제거 후에도 SharedPreference가 남아있음 (0) | 2020.01.08 |
[Android] android studio 전체 프로젝트에 폰트 적용 (0) | 2019.12.20 |
[Android] 라디오버튼 alertDialog (0) | 2019.12.17 |