Glide for the first time

Glide basic usage reference load local pictures

File file = new File(getExternalCacheDir() + “/image.jpg”);

Glide.with(this).load(file).into(imageView); /

Int resource = r.rawable. Image;

Glide.with(this).load(resource).into(imageView);

Byte [] image = getImageBytes();

Glide.with(this).load(image).into(imageView);

// Load the Uri object Uri imageUri = getImageUri();

Glide.with(this).load(imageUri).into(imageView);

The with() method is a set of static methods in the Glide class, and we started going to Glide. With () to see what’s going on,

The with() method we see all the time is overloaded

Then scroll down to see what the getRetriever () method does. I can translate it by computer.

GetRetriever () here is obviously ready for nullifying the life cycle. It also reminds us that we should also pay attention to nullifying and type determination if we need to write our own code. Then go to getRequestManagerRetriever () this method we went on to look down

GetRequestManagerRetriever () RequestManagerRetriever (request manager retrieval) in the direct return out that we have to want to know what request manager retrieval device is?

RequestManagerRetriever

Go inside and see what works for the RequestManager, and then see what works for the RequestManager

That looks familiar, that’s the corresponding get () method that we’re calling outside so let’s look inside the method

RequestManager.get()

In the RequestManagerRetriever class, you need to invoke the get method from the ApplicationContext if the context is not the main thread:

GetApplicationManager () if called from the main thread, whether context, Fragment, or Activtiy, ends with fragmentGet and supportFragmentGet:

fragmentGet

SupportFragmentGet either adds a Fragment to the current page, either adding a V4 package or adding android.app. fragment (deprecated and still in use). First obtained a through getSupportRequestManagerFragment SupportRequestManagerFragment objects:

SupportRequestManagerFragment: without a view of the fragments, hold ActivityFragmentLifecycle instance, and hold RequestManager instance, The RequestManager can start, stop, and manage Glide requests requests.

getSupportRequestManagerFragment() 1. Create a Fragment with no view and bind it to the current activity.

Lifecycle of the Fragment will be passed in to the RequestManager. Lifecycle of the fragment will be passed in to the RequestManager. 3, obtain fragments object, according to the first tag to look for, if not from memory lookup, pendingSupportRequestManagerFragments is a storage fragments HashMap instance, there is no new one. Because Glide. WTH (context) is finally returned to a RequestManagert object, so this step over here, then add what’s the use of the fragments, we see SupportRequestManagerFragment core

method

SupportRequestManagerFragment 1

SupportRequestManagerFragment 2 here why monitoring fragments of life cycle, actually you should know that Fragment is attached to the Activity of the Activity of the life cycle in the Fragment, So listen for the Fragment.

ActivityFragmentLifecycle can clearly know the life cycle inside specific what went in to look at!

ActivityFragmentLifecycle annotation translation

ActivityFragmentLifecycle life cycle

OnStart () 1: when creating fragments will create ActivityFragmentLifecycle object; Lifecycle methods will be called in methods of the Fragment Lifecycle to inform the RequestManager. Lifecycle will ultimately call LifecycleListener to inform the relevant implementation class, namely the RequestManager.

Lifecycle Lifecycle interface implemented by Glide, registered with the RequestManager instantiated in the RequestManagerFactory we just explained, and then added Lifecycle callback listener in the constructor. Let’s see.

RequestManager

RequestManager RequestManage

A small summary

Summary from a big shot

1, create a view of the fragments, specifically is SupportRequestManagerFragment/RequestManagerFragment, and bind to the current Activity, The Fragment is aware of the Activity’s life cycle; Lifecycle and LifecycleListener are initialized when fragments are created and methods onStart(), onStop(), onDestroy() are called. Lifecycle object is passed when RequestManager is created and LifecycleListener implements the LifecycleListener interface. So that when the lifecycle changes, the interface callback notifies the RequestManager to process the request. It’s a RequestManager object, and Glide will use the parameter we passed to the with() method to determine the image load life cycle. Let’s start with the second step, load().

Reference links: blog.csdn.net/liumeng1233…

Reference links: www.jianshu.com/p/79dd4953e…

Reference links: www.jianshu.com/p/7194e151d…

Reference links: www.jianshu.com/p/36092fe62…