解决:使用多线程延迟加载avif图片,推荐使用HandlerThread来开启线程
代码参考如下:
private HandlerThread mImageLoadThread;
private Handler mImageLoadHandler;
private void init(){
mImageLoadThread = new HandlerThread(TAG + "-ImageLoadThread");
mImageLoadThread.start();
mImageLoadHandler = new ImageLoadHandler(mImageLoadThread.getLooper());
mImageLoadHandler.sendEmptyMessage(MSG_LOAD_HDR_IMAGE);
}
private void loadBitmap() {...}
private class ImageLoadHandler extends Handler {
ImageLoadHandler(Looper looper) {
super(looper);
}
@Override
public void handleMessage(Message msg) {
Log.i(TAG, "handleMessage msg.what = " + msg.what);
if (msg.what == MSG_LOAD_HDR_IMAGE) {
loadBitmap();
}
}
}
相关: