您的位置:首页 > 移动开发 > Android开发

Android LruCache : how to put and get user's data

2017-10-02 19:31 513 查看
package zhangphil.cache;

import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.util.LruCache;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

int CACHE_SIZE = 8 * 1024 * 1024;
LruCache<String, Bitmap> mLruCache = new LruCache(CACHE_SIZE);

int count = 5;

String key;
Bitmap bmp;
for (int i = 0; i < count; i++) {
key = String.valueOf(i);
bmp = Bitmap.createBitmap(i + 1, i + 2, Bitmap.Config.ARGB_8888);

mLruCache.put(key, bmp);
}

for (int i = 0; i < count; i++) {
key = String.valueOf(i);
bmp = mLruCache.get(key);
Log.d("key:" + key, "value:" + bmp.getWidth() + "," + bmp.getHeight());
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: