Android image caching method based on softreference

This article gives an example of how Android caches images based on softreference. Share with you for your reference, as follows:

Softreference in Java is the soft reference of the object. If an object has soft references and enough memory space, the garbage collector will not recycle it; If the memory space is insufficient, the memory of these objects will be reclaimed. As long as the garbage collector does not recycle it, the object can be used by the program. Soft references can be used to implement memory sensitive caching. Using soft reference can prevent memory leakage and enhance the robustness of the program.

The feature of softreference is that an instance of softreference stores a soft reference to a Java object. The existence of the soft reference does not prevent the garbage collection thread from recycling the Java object. That is, once the softreference saves the soft reference to a Java object, the get () method provided by the softreference class returns the strong reference of the Java object before the garbage thread recycles the Java object. In addition, once the garbage thread recycles the Java object, the get () method will return null

Cache soft referenced bitmap objects with map collection:

Note: if the program needs to load a large number of pictures from the Internet, consider establishing a temporary folder on sdcard to cache these pictures

For more Android related content, readers who are interested can view the topics on this site: summary of Android cache operation skills, summary of memory and cache skills for Android development, summary of Android graphics and image processing skills, introduction and advanced tutorial for Android development, summary of Android debugging skills and common problem solutions Summary of Android multimedia operation skills (audio, video, recording, etc.), summary of Android basic components usage, summary of Android view skills, summary of Android layout skills and summary of Android control usage

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>