毕加索有问题,我遇到了崩溃事件:
Fatal Exception: java.util.concurrent.RejectedExecutionException: Task com.squareup.picasso.PicassoExecutorService$PicassoFutureTask@41a39a38 rejected from com.squareup.picasso.PicassoExecutorService@41acc1d0[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1967)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:782)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1303)
at com.squareup.picasso.PicassoExecutorService.submit(PicassoExecutorService.java:88)
at com.squareup.picasso.Dispatcher.performSubmit(Dispatcher.java:202)
at com.squareup.picasso.Dispatcher.performSubmit(Dispatcher.java:175)
at com.squareup.picasso.Dispatcher$DispatcherHandler.handleMessage(Dispatcher.java:482)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.os.HandlerThread.run(HandlerThread.java:60)
这是我在onResume()中创建毕加索的方式:
final Picasso.Builder builder = new Picasso.Builder(context);
builder.indicatorsEnabled(BuildConfig.DEBUG);
builder.defaultBitmapConfig(Bitmap.Config.RGB_565);
final long cacheSize = (long) (getAvailableRam() * 0.5F);
builder.memoryCache(new LruCache((int) cacheSize));
builder.listener(_listener);
_picasso = builder.build();
并在onPause()中:
if (_picasso != null) {
_picasso.shutdown();
_picasso = null;
}
有什么建议吗?
答案 0 :(得分:0)
可能问题在于停机。我建议先取消所有任务,然后关闭毕加索:)
结帐:https://github.com/square/picasso/issues/329
简单快速的解决方案。
使用picasso的单个实例
/** Stops this instance from accepting further requests. */
public void shutdown() {
if (this == singleton) {
throw new UnsupportedOperationException("Default singleton instance cannot be shutdown.");
}
if (shutdown) {
return;
}
cache.clear();
cleanupThread.shutdown();
stats.shutdown();
dispatcher.shutdown();
for (DeferredRequestCreator deferredRequestCreator : targetToDeferredRequestCreator.values()) {
deferredRequestCreator.cancel();
}
targetToDeferredRequestCreator.clear();
shutdown = true;
}
检查:
public void cancelTag(Object tag) {
checkMain();
if (tag == null) {
throw new IllegalArgumentException("Cannot cancel requests with null tag.");
}
List<Action> actions = new ArrayList<Action>(targetToAction.values());
//noinspection ForLoopReplaceableByForEach
for (int i = 0, n = actions.size(); i < n; i++) {
Action action = actions.get(i);
if (tag.equals(action.getTag())) {
cancelExistingRequest(action.getTarget());
}
}
List<DeferredRequestCreator> deferredRequestCreators =
new ArrayList<DeferredRequestCreator>(targetToDeferredRequestCreator.values());
//noinspection ForLoopReplaceableByForEach
for (int i = 0, n = deferredRequestCreators.size(); i < n; i++) {
DeferredRequestCreator deferredRequestCreator = deferredRequestCreators.get(i);
if (tag.equals(deferredRequestCreator.getTag())) {
deferredRequestCreator.cancel();
}
}
}