Efficient image display-original Android official website translation
Translator: I am in an Android project team that I just created. OutOfMemory has been bothering me for a long time. I accidentally saw a suggestion in Stack Overflow and read this article. This article is not a high-end technology, and there are already some open-source components that can solve this problem. However, this article comprehensively describes how to deal with similar problems from the perspective of principles, which gives me a lot of inspiration. I am at a limited level. I have been searching for words during the translation process. Please forgive me if the translation is not in place.
Learning how to load images in Android not only helps you create a responsive UI, but also avoids exceeding the application's memory limit, thus avoiding OutOfMemory exceptions. If you are not careful enough, loading the Bitmap object will quickly consume the available memory of the application, causing the program to crash: java. lang. OutofMemoryError: bitmap size exceeds VM budget.
1. Exercise caution when loading images in Android due to the following reasons:
1. Mobile devices usually have limited system resources. Each app on the Android device can obtain at least 16 MB of available memory. Android Compatibility Document Android Compatibility Definition Document
2. Bitamp objects consume a lot of memory, especially for applications with rich images or photos. For example, a Galaxy Nexus camera (5 million pixels) can display a maximum
2. The following courses will show you how to quickly and securely load images in the Android environment.
Efficient image loading: describes how to ensure that a large image is loaded without exceeding the application memory limit.
Image processing outside the UI thread: Image operations (resetting the size, remote downloads, etc.) never occupy the UI thread. This section describes how to use AsyncTask in the background thread to process images and explain how to handle concurrency issues.
Cached images: This section describes how to use memory and external memory to cache images and improve UI response and mobility when loading images.
Image Memory Management: This section describes how to manage image memory to optimize the performance of applications.
Display images in the UI: This section combines the previous article to show you how to use background threads and image caches to load images into components such as ViewPager or GridView.
Click here to download the sample source code
Original article link