Skip to content

Commit 5b2c026

Browse files
committed
Returned ImageLoader.stop()
1 parent d063841 commit 5b2c026

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

library/src/com/nostra13/universalimageloader/core/ImageLoader.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -453,17 +453,21 @@ public void resume() {
453453
}
454454

455455
/**
456-
* Clears current configuration. Stops all running display image tasks, discards all other scheduled tasks (true for
457-
* built-in task executors, false - for
458-
* {@linkplain ImageLoaderConfiguration.Builder#taskExecutor(java.util.concurrent.ExecutorService) custom task
459-
* executors}).<br />
460-
* <br />
456+
* Cancels all running and scheduled display image tasks.<br />
457+
* ImageLoader still can be used after calling this method.
458+
*/
459+
public void stop() {
460+
engine.stop();
461+
}
462+
463+
/**
464+
* {@linkplain #stop() Stops ImageLoader} and clears current configuration. <br />
461465
* You can {@linkplain #init(ImageLoaderConfiguration) init} ImageLoader with new configuration after calling this
462466
* method.
463467
*/
464468
public void destroy() {
465469
if (configuration != null && configuration.loggingEnabled) L.d(LOG_DESTROY);
466-
engine.destroy();
470+
stop();
467471
engine = null;
468472
configuration = null;
469473
}

library/src/com/nostra13/universalimageloader/core/ImageLoaderEngine.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ void submit(final LoadAndDisplayImageTask task) {
6868
@Override
6969
public void run() {
7070
boolean isImageCachedOnDisc = configuration.discCache.get(task.getLoadingUri()).exists();
71+
initExecutorsIfNeed();
7172
if (isImageCachedOnDisc) {
7273
taskExecutorForCachedImages.execute(task);
7374
} else {
@@ -79,9 +80,23 @@ public void run() {
7980

8081
/** Submits task to execution pool */
8182
void submit(ProcessAndDisplayImageTask task) {
83+
initExecutorsIfNeed();
8284
taskExecutorForCachedImages.execute(task);
8385
}
8486

87+
private void initExecutorsIfNeed() {
88+
if (taskExecutor == null) {
89+
taskExecutor = createTaskExecutor();
90+
}
91+
if (taskExecutorForCachedImages == null) {
92+
taskExecutorForCachedImages = createTaskExecutor();
93+
}
94+
}
95+
96+
private Executor createTaskExecutor() {
97+
return DefaultConfigurationFactory.createExecutor(configuration.threadPoolSize, configuration.threadPriority, configuration.tasksProcessingType);
98+
}
99+
85100
/** Returns URI of image which is loading at this moment into passed {@link ImageView} */
86101
String getLoadingUriForView(ImageView imageView) {
87102
return cacheKeysForImageViews.get(imageView.hashCode());
@@ -145,24 +160,17 @@ void resume() {
145160
}
146161
}
147162

148-
/** Stops all running display image tasks, discards all other scheduled tasks. Clears internal data. */
149-
void destroy() {
163+
/** Stops engine, cancels all running and scheduled display image tasks. Clears internal data. */
164+
void stop() {
150165
if (!configuration.customExecutor) {
151-
((ExecutorService) taskExecutor).shutdownNow();
166+
taskExecutor = null;
152167
}
153168
if (!configuration.customExecutorForCachedImages) {
154-
((ExecutorService) taskExecutorForCachedImages).shutdownNow();
155-
}
156-
if (taskDistributor != null) {
157-
taskDistributor.shutdownNow();
169+
taskExecutorForCachedImages = null;
158170
}
159171

160172
cacheKeysForImageViews.clear();
161173
uriLocks.clear();
162-
163-
taskExecutor = null;
164-
taskExecutorForCachedImages = null;
165-
taskDistributor = null;
166174
}
167175

168176
ReentrantLock getLockForUri(String uri) {

0 commit comments

Comments
 (0)