Glide加载图片不刷新

三方图片框架这么几年也就三四个,当然了也可以自己封装,如何选择框架主要看自己的项目里面图片多少来达到一个平衡点,现有用的最多的还是Glide框架,不需要去管如何缓存,加载机制;

先老生常谈一下,上源码

//绑定Activity得生命周期

//绑定Fragment得生命周期

    @NonNull
    private static RequestManagerRetriever getRetriever(@Nullable Context context) {
        Preconditions.checkNotNull(context, "You cannot start a load on a not yet attached View or a Fragment where getActivity() returns null (which usually occurs when getActivity() is called before the Fragment is attached or after the Fragment is destroyed).");
        return get(context).getRequestManagerRetriever();
    }

    @NonNull
    public static RequestManager with(@NonNull Context context) {
        return getRetriever(context).get(context);
    }

    @NonNull
    public static RequestManager with(@NonNull Activity activity) {
        return getRetriever(activity).get(activity);
    }

    @NonNull
    public static RequestManager with(@NonNull FragmentActivity activity) {
        return getRetriever(activity).get(activity);
    }

    @NonNull
    public static RequestManager with(@NonNull Fragment fragment) {
        return getRetriever(fragment.getActivity()).get(fragment);
    }

    /** @deprecated */
    @Deprecated
    @NonNull
    public static RequestManager with(@NonNull android.app.Fragment fragment) {
        return getRetriever(fragment.getActivity()).get(fragment);
    }

    @NonNull
    public static RequestManager with(@NonNull View view) {
        return getRetriever(view.getContext()).get(view);
    }

with如果传入Application.this作为参数时,Glide的加载不受当前Activity生命周期影响,但这会导致即使Activity结束后,仍然继续加载图片(内存泄漏),还没办法刷新图片;

最近在做项目时发现,仅仅是修改了一下上下文导致了图片加载第一次加载正常,再次打开界面加载默认图片,抓包,打印数据发现URL是有的,偏偏在Glide加载时展示得默认图片,怀疑是不是缓存得问题,设置之后发现没有半毛钱关系,最后传递了当前界面得上下文就恢复正常了;


之前为了一个优化修改了当前类得上下文,直接持有MyApplication的上下文导致一直在持有,解决问题的能力;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一个小狼娃

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值