Executor of FeedImageLoader can now be shut down manually

This commit is contained in:
daniel oeh 2012-08-03 20:04:01 +02:00
parent e170605ebc
commit b6b6129feb
2 changed files with 23 additions and 10 deletions

View File

@ -59,16 +59,7 @@ public class FeedImageLoader {
private FeedImageLoader() {
handler = new Handler();
executor = Executors.newFixedThreadPool(Runtime.getRuntime()
.availableProcessors(), new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setPriority(Thread.MIN_PRIORITY);
return t;
}
});
executor = createExecutor();
coverCache = new LruCache<String, Bitmap>(coverCacheSize) {
@ -99,6 +90,19 @@ public class FeedImageLoader {
};
}
private ExecutorService createExecutor() {
return Executors.newFixedThreadPool(Runtime.getRuntime()
.availableProcessors(), new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setPriority(Thread.MIN_PRIORITY);
return t;
}
});
}
public static FeedImageLoader getInstance() {
if (singleton == null) {
singleton = new FeedImageLoader();
@ -185,6 +189,13 @@ public class FeedImageLoader {
target.setImageResource(R.drawable.default_cover);
}
}
public void clearExecutorQueue() {
executor.shutdownNow();
if (AppConfig.DEBUG) Log.d(TAG, "Executor was shut down.");
executor = createExecutor();
}
public void wipeImageCache() {
coverCache.evictAll();

View File

@ -20,6 +20,7 @@ import com.actionbarsherlock.app.SherlockListFragment;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.MiroGuideChannelListAdapter;
import de.danoeh.antennapod.asynctask.FeedImageLoader;
import de.danoeh.antennapod.miroguide.con.MiroGuideException;
import de.danoeh.antennapod.miroguide.con.MiroGuideService;
import de.danoeh.antennapod.miroguide.model.MiroChannel;
@ -122,6 +123,7 @@ public class MiroGuideChannellistFragment extends SherlockListFragment {
if (channelLoader != null) {
channelLoader.cancel(true);
}
FeedImageLoader.getInstance().clearExecutorQueue();
}
@Override