Is it bad practice to call
getResources().getDrawable()
or BitmapFactory.decodeResource()
from the UI thread on Android? I'm just wondering since I have this situation where I want to show a loding image in my view while I execute a background operation, but Im still calling either one of the above methods... almost every project I look at seems to execute either method on any thread without second thought, but I'm just looking for best practices.
Fast forward 3 years since I asked this question, and I think the short answer is "Just use Picasso or Glide". I think the long answer is "it depends". It depends on the size of the Image/drawable. For BitmapFactory#decodeResource
, you should do everything you can to stay off the main thread. If I'm trying to show a placeholder image, best practice is that it should be packaged in your app with a reasonable size with fits with your design.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With