Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you safely call "getDrawable" or "decodeResource" on the UI thread in Android

Tags:

android

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.

like image 632
Vijay Sharma Avatar asked Nov 03 '22 19:11

Vijay Sharma


1 Answers

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.

like image 165
Vijay Sharma Avatar answered Nov 13 '22 01:11

Vijay Sharma