How does the Android Image Loading library solve the slow loading issue? | by Amit Shekhar | Sep, 2022

I am Amit Shekhar, a mentor serving to developers in acquiring superior-spending tech positions.

In this blog, we are going to master how the Android Picture Loading library solves the slow loading difficulty of images.

This post was at first published at amitshekhar.me.

Loading photos rapidly is extremely critical for a greater user knowledge. We need to discover how it is accomplished less than the hood.

These concepts are critical when it arrives to Android Interviews.

So, I was examining the supply code of different Image Loading libraries in Android like Glide, Fresco, etc.

These libraries do a whole lot of things internally for us so that we can just use them and get our tasks finished very easily. They make our daily life less complicated.

One of the matters that they do is that they load the illustrations or photos as rapidly as probable.

Let’s study how the Android Graphic Loading library hundreds the impression fast.

Sluggish loading is a different challenge when it will come to loading a bitmap into the view. A person of the big good reasons for gradual loading is that we do not cancel the undertaking like downloading, or decoding a bitmap even when the watch is out of the window or that job is no far more wanted, therefore there are quite a few tasks that are becoming completed even however we do not have to have them, so it normally takes time for the precise picture to load which just arrived in the window.

The impression loading libraries like Glide and Fresco consider treatment of this, they terminate all the duties effectively and only load the pictures which are seen to the user.

These libraries are informed of the exercise, and fragment lifecycle, this way they know which graphic downloading or bitmap decoding jobs will need to be canceled.

You ought to be considering about how they are conscious of the activity and fragment lifecycle. I will demonstrate this to you by getting the example of Glide.

We use Glide like this:

Glide.with(fragment)
.load(url)
.into(imageView)

Right here, we can see that we are passing the fragment, this way Glide subscribes to the Fragment’s lifecycle activities. Equally, it takes place for the exercise and the check out.

This is how they fix the sluggish image loading problem by canceling the tasks that are no more needed at the correct time. One particular far more issue that these libraries do is that they cache the photographs at two levels. Let’s discover about it also.

They create a memory cache so that they do not have to decode the impression again and all over again as decoding takes time. These libraries build a cache of some configurable measurement to catch the bitmaps.

They keep two degrees of caching:

When we offer the URL to the libraries, they do the subsequent:

  • They look at if the graphic with that URL critical is accessible in the memory cache or not.
  • If existing in the memory cache, they just demonstrate the bitmap by taking it from the memory cache.
  • If not present in the memory cache, they test in the disk cache.
  • If present in the disk cache, they load the bitmap from the disk, also puts it in the memory cache, and load the bitmap into the see.
  • If not present in the disk cache, they obtain the graphic from the community, put it in the disk cache, also put it in the memory cache, and load the bitmap into the look at.

This way they make loading speedy as demonstrating directly from the memory cache is always more rapidly.

So largely, they do these two issues as follows:

  • Terminate the duties that are no more required at the correct time.
  • Cache the photographs at two degrees.

This was all about how the Android Picture Loading library solves the slow loading challenge of photographs.

We will discover a lot more points that these libraries do in our impending web site write-up.

Which is it for now.

Thanks

Amit Shekhar

You can connect with me on:

Next Post

Sylvester Stallone Posts Photo With Estranged Wife Jennifer Flavin Amid Divorce

Sylvester Stallone seemed perplexed about divorcing Jennifer Flavin, his lengthy-expression wife. The “Rocky” actor shared intimate illustrations or photos of his ex-spouse on Instagram a handful of days right after covering up a 2nd tattoo honoring her. “Wonderful….” The two-slide carousel’s initially graphic, which showcased the couple strolling as a […]
Sylvester Stallone Posts Photo With Estranged Wife Jennifer Flavin Amid Divorce

You May Like