问题标签 [android-lru-cache]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
1434 浏览

android - Android: LruCache issue with Bitmap

I have a global bitmap cache using LruCache class. when loading thumbnails for the listview, the cache is used first. It works just OK.

But one issue is: sometimes the Bitmap instance from the cache cannot be displayed on the listview. it seems such bitmap from cache is not valid any more. I have checked the bitmap from cache if it is not null and if it is not recycled, but it still seems such bitmap cannot be displayed (even it is not null and it is not recycled).

The cache class:

and the code to use the cache is in the Adapter class which is subclass of CursorAdapter:

the code of DownloadImageTask:

any help will be appreciated. Thanks!

Updates: I have followed the link suggested by greywolf82: section "Handle Configuration Changes". I put the following attribute in my activity class and the two fragment classes:

public LruCache mMemoryCache;

In the activity class, I try to initialize the cache when calling the fragment:

in the fragment class: setRetainInstance(true);

and I pass the cache instance to the adapter constructor so that the adapter can use the cache.

but I still got the same issue.

Update 2:

the two adapter classes with changes to accept the LruCache instance:

NewsCursorAdapter:

the list adapter, NewsTopicItemAdapter:

Update 3: I have attached the debug information from eclipse: the 1st picture is the working bitmap, and the 2nd one is the non-working bitmap from cache. I didn't find anything suspicious.

The debug information of the working bitmap from the cache:

The debug information of the working bitmap from the cache

The debug information of the non-working bitmap from the cache:

The debug information of the non-working bitmap from the cache

0 投票
1 回答
106 浏览

android - android LruCache 真机

我正在尝试使用 RestFull Web 服务创建 android 应用程序,并在使用和使用 Lrucahe 保存图像时完成所有应用程序工作,但是当在真实设备上安装应用程序时抛出异常:java.lang.noclassdeffounderror android.util.lrucache 我的设备目标是 2.3 .6

0 投票
1 回答
115 浏览

android - LruCache 为指定的键返回错误的位图

我对 Android 开发非常陌生。

我遇到了从 LruBitmapCache 获取正确位图的问题。我使用 UUID 生成唯一 ID,我不使用 URL,因为我在画布上生成位图。(我getDrawingCache()从我的视图复制到一个新的位图(使用副本),然后将副本存储到缓存中)。

出于某种原因,在我存储位图后,当我访问它时,它最终成为另一个 id 的位图......有时会发生这种情况。有任何想法吗?

我使用 currentIndex 来跟踪我在 cachedKeys 数组中的位置(我想按顺序保存并浏览画布上的 bitamp)。我想我正在更新缓存中的条目错误...

0 投票
1 回答
1588 浏览

android - 使用 DiskLruCache 实现图像 Lru 缓存

我正在尝试使用 jake wharton DiskLruCache 库实现基于磁盘的图像 lru 缓存。链接到图书馆。我正在使用这里的代码片段。

我遇到问题的方法是这个

其中 editor.newOutputStream(0) 不存在,而这个

其中 snapshot.getInputStream(0) 也不存在。

我究竟做错了什么?我已将 jar 与库一起放置,一切都很好,这些方法是否已从 DiskLruCache 库中删除?现在还有其他方法可以做到这一点吗?我找不到任何示例或教程。

库版本是最新的disklrucache-2.0.2

0 投票
0 回答
281 浏览

android - 从活动的上下文中初始化 ImageCache

我试图理解这个样本与我的匹配:(DisplayingBitmaps)

http://developer.android.com/downloads/samples/DisplayingBitmaps.zip

此代码使用管理位图缓​​存的类 ImageCache:

}

在示例中,缓存 (LRUCache) 使用片段 (ImageGridFragment) 中的以下代码进行初始化:

ImageWorker 使用片段上下文初始化 ImageCache 中的缓存的方法:

如何使用此类从活动上下文中“实例化”和初始化 cahe?

谢谢

0 投票
2 回答
5897 浏览

android - 是否可以更改毕加索用于图像的缓存大小?

我正在使用 Picasso 从 URL (http://) 加载图像。有时当我尝试使用毕加索的fetch()方法“预加载”图像时,图像不会被缓存。我猜是因为它的尺寸太大了。

阅读这个问题的答案,但setCache()我似乎无法识别,我什至在毕加索文档中都找不到。

有没有办法改变毕加索用于位图的缓存大小?

0 投票
1 回答
168 浏览

android - 如何使用 RoboSpice 缓存类型

注意:这是 Android 缓存机制新手的一般问题。

为什么 RS 在FlickrSpiceService示例中使用 LRU 缓存?

LruCacheBitmapObjectPersister

为什么不删除它并InFileBitmapObjectPersister像这样使用:

0 投票
0 回答
211 浏览

android - 使用 Volley 和 ListView 的磁盘缓存真的很慢

我正在尝试将此库https://github.com/JakeWharton/DiskLruCache用于磁盘缓存,但是当我的 ListView 中有很多图像时我遇到了问题。滞后有时真的很糟糕。

我使用了以下 GitHub 存储库中的方法:https ://github.com/rdrobinson3/VolleyImageCacheExample

问题是对于更大的图像,有很大的滞后,没有很好的滚动体验。

我该如何改进这种方法?

我可以public Bitmap putBitmap( String key )将位图保存在后台线程中,但存在public Bitmap getBitmap( String key )无法在后台线程中完成的问题。

谢谢你。

0 投票
1 回答
473 浏览

android - 实现 LruCache 以缓存位图图像

在我的应用程序中,我正在从 Internet 获取提要。feed 包含一些文本信息和图像。我必须将图像存储在LruCache中,因为我参考了Google 开发者网站并按照那里所示的方式实现。这个实现工作正常。但由于我的应用程序支持 api 级别 10,它显示一些错误分配缓存大小,我无法声明缓存正弦的大小我正在使用 bitmap.getByteCount() 它显示添加@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)符号,并且当我在 android 2.3 中打开应用程序时应用程序停止回应

代码

我如何也支持 api 级别 10,有什么办法吗?

0 投票
1 回答
458 浏览

java - 获取 LRUCache Android 中使用的当前内存

为了测试,我想查看我的 LRU 缓存中当前使用了多少 kB / MB。我将总大小设置为 4096。

有没有这样的功能:

或者