3
안녕하세요 저는 다음에 애플리케이션을 시작할 때 Android 장치에 저장해야하는 비트 맵 Hasmap이 있습니다.Android HashMap 직렬화/직렬화
내 해시 맵은 다음과 같습니다, 1000 비트 맵까지 포함 :
private static HashMap <String, Bitmap> cache = new HashMap<String, Bitmap>();
안녕하세요 저는 다음에 애플리케이션을 시작할 때 Android 장치에 저장해야하는 비트 맵 Hasmap이 있습니다.Android HashMap 직렬화/직렬화
내 해시 맵은 다음과 같습니다, 1000 비트 맵까지 포함 :
private static HashMap <String, Bitmap> cache = new HashMap<String, Bitmap>();
당신은 (AbstractMap를 사용하여)지도의 확장을 만들 고려하고 관련 기능을 오버라이드 (override) 할 수 있습니다. 일반적으로 확장의 구조는 다음과 같아야합니다.
this.objectMap = Collections.synchronizedMap(new LinkedHashMap() {
@Override
protected boolean removeEldestEntry(LinkedHashMap.Entry eldest) {
if (size() > HARD_CACHE_CAPACITY) {
// remove from cache, pass to secondary SoftReference cache or directly to the disk
}
}
});
@Override
public Bitmap get(Object key) {
if(key != null) {
// first level, hard cache
if(objectMap.containsKey(key)) {
return objectMap.get(key);
}
// soft reference cache
if(secondaryCache.containsKey(key)) {
return secondaryCache.get(key);
}
// get from disk if it is not in hard or soft cache
String fileName = "Disk-" + key + ".txt";
File f = new File(cacheDir, fileName);
if(f.exists()) {
// put this back to the hard cache
Bitmap object = readFromReader(f);
if(object != null) {
objectMap.put((String)key, object);
return object;
}
}
}
return null; // unable to get from any data source
}
마찬가지로 당신 넣어 사용하면 응용 프로그램을 다시 초기화 할 때 그래서 당신은 단지지도의 인스턴스를 만들 수 있습니다, 우선은 나중에 사용하기 위해 디스크에 넣어되어야합니다 신장. 원하는 경우 앱에서 가장 최근에 사용한 항목별로 해시 맵을 미리로드 할 수도 있습니다. 기본적으로 AbstractMap을 확장하면 1000 비트 맵으로 메모리를 없애지 않고도 유연성을 얻을 수 있습니다. 희망이 도움이
같은 uqestions에 관심이있을 것입니다 .. – cV2