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); }
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/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