In android you can load resources outside of ui thread

I have, in our opinion, a simple question. I want to know if you can safely load resources from a non-ui stream. I'm talking about things in the "res" folder. I just can't find any documentation that definitively answers this question. There are a lot of references in the SDK related to what is not allowed in the UI thread. I have never seen anything that indicated loading resources this way.

For example, can this code be called from a background thread?   Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_resource);

Does it help me to remove the context.getResources () part and only execute:   Bitmap icon = BitmapFactory.decodeResource(res, R.drawable.icon_resource);

+3


source to share


1 answer


Yes you can!

But that depends a lot on how the API handles such calls. For example. if the API expects a context, then you might have to provide the correct option by saving the UI context and passing it to the background thread.



However, when it comes to customizing the UI components, you have to go back to the UI thread.

+5


source







All Articles