Glide取消图片加载
1.在任务刚开始时;
2.在EngineJob中,Future.cancel(true)
3.在加载完成,但没有加载到控件;
RequestManager.java:
public void pauseRequests() { Util.assertMainThread(); requestTracker.pauseRequests(); }
RequestTracker.java:
public void pauseRequests() { isPaused = true; for (Request request : Util.getSnapshot(requests)) { if (request.isRunning()) { request.pause(); pendingRequests.add(request); } } }
GenericRequest.java:
@Override public void pause() { clear(); status = Status.PAUSED; }
GenericRequest.LoadStatus.java:
public void cancel() { engineJob.removeCallback(cb); }
EngineJob.java:
public void removeCallback(ResourceCallback cb) { Util.assertMainThread(); if (hasResource || hasException) { addIgnoredCallback(cb); } else { cbs.remove(cb); if (cbs.isEmpty()) { cancel(); } } } void cancel() { if (hasException || hasResource || isCancelled) { return; } engineRunnable.cancel(); Future currentFuture = future; if (currentFuture != null) { currentFuture.cancel(true); } isCancelled = true; listener.onEngineJobCancelled(this, key); }
EngineRunnable.java:
public void cancel() { isCancelled = true; decodeJob.cancel(); }
EngineRunnable.java:
@Override public void run() { if (isCancelled) { return; } Exception exception = null; Resource> resource = null; try { resource = decode(); } catch (Exception e) { if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "Exception decoding", e); } exception = e; } if (isCancelled) { if (resource != null) { resource.recycle(); } return; } if (resource == null) { onLoadFailed(exception); } else { onLoadComplete(resource); } }
EngineJob.java:
private volatile Future> future; void cancel() { if (hasException || hasResource || isCancelled) { return; } engineRunnable.cancel(); Future currentFuture = future; if (currentFuture != null) { currentFuture.cancel(true); } isCancelled = true; listener.onEngineJobCancelled(this, key); }
public void start(EngineRunnable engineRunnable) { this.engineRunnable = engineRunnable; future = diskCacheService.submit(engineRunnable); } @Override public void submitForSource(EngineRunnable runnable) { future = sourceService.submit(runnable); }
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/70704.html
摘要:从这段代码入手分析分析从这段代码可以看出无论传入的是还是或者干脆传入或都会调用这个方法而这个方法生成两个对象对象,并把它加到上对象这两个对象拥有共同的对象对象,当系统调用的生命周期,的生命周期随之被调用来处理列表,将的生命周期与的生命周期联 从这段代码入手分析Glide Glide.with(context) .load(url) .placehol...
阅读 1684·2023-04-25 20:16
阅读 3838·2021-10-09 09:54
阅读 2696·2021-09-04 16:40
阅读 2517·2019-08-30 15:55
阅读 830·2019-08-29 12:37
阅读 2733·2019-08-26 13:55
阅读 2903·2019-08-26 11:42
阅读 3144·2019-08-23 18:26