0
第一项活动在我的应用程序有三个选项卡第一个选项卡包括回收的视图,包含图像和这些图像的列表来自WebService时,点击选项卡上的号码两个或三个,然后点击选项卡编号从WebService加载图像再次我想saveInstance的片段图像的保存实例列表显示他们在RecycleView
第一项活动在我的应用程序有三个选项卡第一个选项卡包括回收的视图,包含图像和这些图像的列表来自WebService时,点击选项卡上的号码两个或三个,然后点击选项卡编号从WebService加载图像再次我想saveInstance的片段图像的保存实例列表显示他们在RecycleView
首先,在您的回收视图的适配器使用Picasso库来显示图像。它具有可直接使用的图像缓存。当您第一次下载图片时,它会被缓存在您的设备上。当您尝试重新下载图像使用相同的URL(当您从第三个标签返回)毕加索会从缓存中显示的图像,并且不会重新下载。
其次,你可以保存在你的片段图像列表。在您的片段覆盖
String BUNDLE_IMAGES = "imgs";
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
ourState.putStringArrayList(BUNDLE_IMAGES , getImageArray())
}
private List<String> getImageArray(){
//your implementation to get image array
}
要恢复对储蓄
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (savedInstanceState != null) {
List<String> images =savedInstanceState.getStringArrayList(BUNDLE_IMAGES);
}
}
更多信息/恢复片段状态:Once for all, how to correctly save instance state of Fragments in back stack?
UPDATE:使用custom图像缓存:
private LruCache<String, Bitmap> mMemoryCache;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
// Get max available VM memory, exceeding this amount will throw an
// OutOfMemory exception. Stored in kilobytes as LruCache takes an
// int in its constructor.
final int maxMemory = (int) (Runtime.getRuntime().maxMemory()/1024);
// Use 1/8th of the available memory for this memory cache.
final int cacheSize = maxMemory/8;
mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
@Override
protected int sizeOf(String key, Bitmap bitmap) {
// The cache size will be measured in kilobytes rather than
// number of items.
return bitmap.getByteCount()/1024;
}
};
...
}
public void addBitmapToMemoryCache(String key, Bitmap bitmap) {
if (getBitmapFromMemCache(key) == null) {
mMemoryCache.put(key, bitmap);
}
}
public Bitmap getBitmapFromMemCache(String key) {
return mMemoryCache.get(key);
}
首先我' (AWS)亚马逊Web服务工作和下载图像不使用URl – yousef
可以哟你可以帮助我在下载后制作缓存图像,而不使用Picasso @ HellCat2405 – yousef