private String getAsyncLoaderStatus() { String status = "null"; synchronized (asyncLoaderLock) { if (asyncLoader != null) { status = asyncLoader.getStatus().name(); } } return status; }
private boolean taskIsNotRunning() { boolean isNotRunning = true; synchronized (asyncLoaderLock) { if (asyncLoader != null) { isNotRunning = (asyncLoader.getStatus() != Status.RUNNING); } } return isNotRunning; }
private boolean cancelAsyncTask(String callerMethod) { boolean cancelled = false; synchronized (asyncLoaderLock) { if (MyLog.isVerboseEnabled() && asyncLoader != null) { logV(callerMethod + "-cancelAsyncTask", "status:" + getAsyncLoaderStatus()); } if (asyncLoader != null && asyncLoader.getStatus() == Status.RUNNING) { if (asyncLoader.cancel(true)) { logV(callerMethod, "task cancelled"); } else { logV(callerMethod, "couldn't cancel task"); } } asyncLoader = null; cancelled = true; } return cancelled; }
private void restartLoader() { final String method = "restartLoader"; boolean ended = false; synchronized (asyncLoaderLock) { if (MyLog.isVerboseEnabled() && asyncLoader != null) { logV(method, "status:" + getAsyncLoaderStatus()); } if (cancelAsyncTask(method)) { try { asyncLoader = new AsyncLoader(); asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } catch (Exception e) { logD(method, "", e); ended = true; asyncLoader = null; } } } if (ended) { logV(method, "deliver null as result"); deliverResultsAndClean(null); } }