Topic:
When the network is bad, how to optimize the load picture of the network when stalling?
Ideas:
Consider both the loading of the picture itself and the storage of the phone
Workaround: 1. Find a replacement for an existing picture format
In a number of image formats, Google's WEBP is selected. The reason for this is simple: high compression efficiency and good support for Android (Google, after all). After using WebP, the traffic is nearly 25% to 35 compared to the JPG format, and the traffic is nearly 80% compared to PNG-formatted images. The most important thing is that the image quality has not changed after using WEBP.
2. Load images according to the ability of the device to process pictures
Previously, all images were uniformly loaded with the maximum resolution, so that the user was free to zoom in and out of the picture. Later, the app's first loaded image size fits the image window size. If thumbnails are needed, the app loads only thumbnail-sized images, users need higher-resolution images, apps can load, and previously uniformly loaded images with the highest resolution.
3. Adjust the policies for caching and reusing pictures.
Use the phone's cache to cache frequently used images, such as the home page image, and the often-opened image setting algorithm.
4. Optimize Network Requests
Use Okhttp. OkHttp supports faster retries under a bad network environment and can also use the SPDY protocol for Fast Concurrent network requests.
Use Okhttp to adjust the image's pre-fetch algorithm to ensure that the image in front of the download queue in the app is prioritized, preventing the queue from being blocked for too long.
Reference: https://greenrobot.me/devnews/facebook-engineer-improve-android-app/
Interview Road (5)-Ali face question Android network picture loading optimization