美文网首页Glide学习
动脑学院Glide预习资料 生命周期管理

动脑学院Glide预习资料 生命周期管理

作者: 十年开发程序员 | 来源:发表于2018-05-09 16:23 被阅读495次

    使用Glide由:

    Glide.with(xx).load(xx).into(view)

    将调用分开,得到

    RequestManager requestManager = Glide.with(this);

    RequestManager即请求管理器,对所有图片加载请求进行管理。

    获得检索.png
    获得RequestManagerRetriever检索RequestManagerRequestManagerRetrieverget代码段如下: 获得RequestManager.png
    在这个代码段中我们看到一个熟悉的身影:FragmentManager
    在Glide中,通过Fragment进行生命周期的管理。

    无论是ViewFragmentActivityFragmentActivity,总能得到一个与之对应的Fragment。而对于Application则会放弃对于管理,所以在使用Glide的时候,一般情况下避免在子线程中使用Glide,而且避免使用Glide.with(application)

    RequestManagerRetriever#fragmentGet.png
    Glide通过向with对应的Context添加一个Fragment(除Application),通过Fragment的onStart、onStop与onDestory进行生命周期的管理。

    在对应的Fragment回调onDestory之后,会clear掉所有的Request。

    在Request中包含上节课中的引用计数Resource。
    如果当前Activity通过Glide使用A图片2次,则引用计数为2+X(其他地方使用次数)。这时候对应的Activity销毁,Fragment回调onDestory,clear这两个Request。这时A图片引用计数为X,X为0则会移出活动资源。

    (没时间了,写不完了写不完了,以后更新~~)

    相关文章

      网友评论

        本文标题:动脑学院Glide预习资料 生命周期管理

        本文链接:https://www.haomeiwen.com/subject/gfjmrftx.html