Glide is an image loading framework, powerful, smart design, elegant and simple call, such as Glide. With (context).load (URL).into (imageview) can complete the image request loading process.
With (context) : This method passes in a context and returns a RequestManager object that has a life cycle. 1. If called from a child thread, a singleton requestManager is created with the lifetime of the APP; 2. If the application context is passed in, the lifecycle of the RequestManager is the lifecycle of the APP; 3. If an Activity /fragment/ View context is passed in, the lifecycle of the RequestManager is the lifecycle of the activity to which they are attached.
If the context is an activity, it looks for an empty fragment based on its tag. If there is an empty fragment, it retrieves the requestManager member of that fragment and returns it. If the RequestManager cannot be found based on the tag, an empty fragment is created, and a RequestManager is created and returned.
An activity corresponds to an empty fragment, and an empty fragment corresponds to a RequestManager. 2. If an activity has multiple image requests, there will be only one empty fragment, a RequestManager; 3. This empty fragment is associated with the Activity and listens for the activity’s life cycle. When the activity’s life cycle changes, it senses and notifies the RequestManager. 4. We pass the context as fine-grained as possible to avoid memory leaks.
If you start an activity, glide starts to load the image, and the activity is destroyed during the loading process, if the context we pass in is the context of the application, the image request will continue, and it will not listen to the life cycle. If we pass in an activity context, then as the activity is destroyed, the empty fragment attached to it will sense it and notify the RequestManager to cancel the request, avoiding resource waste and memory leaks.
Load (URL) : This method is called by the RequestManager, passes in an image link (which could be anything else), and returns a RequestBuilder object. The URL is primarily stored in the member variable Model in the RequestBuilder for simple assignment.
Into (ImageView) : This method is called by the RequestBuilder, passing in the imageView argument. 1. Imageview encapsulation as the target, and create a request the request, if there is a request for previous before the target, then call requestmanager. The clear () to empty, and as the target again. Setrequest (request), Call requestManager.track(target, request) to initiate the asynchronous request. 2. Check whether the page is in paused state. If so, call request.clear () and put the request into the queue to be executed. If the page is not onpaused, call request.begin ().