Home » Java » java – setImage often without blocking UI thread Android-Exceptionshub

java – setImage often without blocking UI thread Android-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have an ImageView. When user presses button I want to change image (it is animation-list) and run this animation. I used to use setImageResource, but it blocks UI thread and causes lags. I can’t predict what image I would set befor user presses button. I tried to preload drawables but it causes OOM, because I have about 30 xmls with animation-list. How can I solve It? To sum up, I want to fastly change image in my ImageView and then start frame animation on it.

How to&Answers:

I think you are performing a fetch operation on the UI thread for the image(either from storage or network call). That is what is causing the lag.

Answer:

You might look into using a library to load up your images. There is one that is really easy to implement called Picasso. It’s been around for a while too, so it should be easy to see some examples.