Loading core/java/android/content/AsyncTaskLoader.java +18 −10 Original line number Diff line number Diff line Loading @@ -19,12 +19,11 @@ package android.content; import android.os.AsyncTask; import android.os.Handler; import android.os.SystemClock; import android.util.Log; import android.util.TimeUtils; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.concurrent.ExecutionException; import java.util.concurrent.CountDownLatch; /** * Abstract Loader that provides an {@link AsyncTask} to do the work. Loading @@ -33,6 +32,7 @@ import java.util.concurrent.ExecutionException; */ public abstract class AsyncTaskLoader<D> extends Loader<D> { private static final String TAG = "AsyncTaskLoader"; final class LoadTask extends AsyncTask<Void, Void, D> implements Runnable { Loading @@ -40,6 +40,8 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> { D result; boolean waiting; private CountDownLatch done = new CountDownLatch(1); /* Runs on a worker thread */ @Override protected D doInBackground(Void... params) { Loading @@ -50,12 +52,20 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> { /* Runs on the UI thread */ @Override protected void onPostExecute(D data) { try { AsyncTaskLoader.this.dispatchOnLoadComplete(this, data); } finally { done.countDown(); } } @Override protected void onCancelled() { try { AsyncTaskLoader.this.dispatchOnCancelled(this, result); } finally { done.countDown(); } } @Override Loading Loading @@ -209,7 +219,8 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> { /** * Locks the current thread until the loader completes the current load * operation. Returns immediately if there is no load operation running. * Should not be called from the UI thread. * Should not be called from the UI thread: calling it from the UI * thread would cause a deadlock. * <p> * Use for testing only. <b>Never</b> call this from a UI thread. */ Loading @@ -217,12 +228,9 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> { LoadTask task = mTask; if (task != null) { try { task.get(); task.done.await(); } catch (InterruptedException e) { Log.w(TAG, e); } catch (ExecutionException e) { throw new RuntimeException("An error occured while executing waitForLoader()", e.getCause()); // Ignore } } } Loading Loading
core/java/android/content/AsyncTaskLoader.java +18 −10 Original line number Diff line number Diff line Loading @@ -19,12 +19,11 @@ package android.content; import android.os.AsyncTask; import android.os.Handler; import android.os.SystemClock; import android.util.Log; import android.util.TimeUtils; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.concurrent.ExecutionException; import java.util.concurrent.CountDownLatch; /** * Abstract Loader that provides an {@link AsyncTask} to do the work. Loading @@ -33,6 +32,7 @@ import java.util.concurrent.ExecutionException; */ public abstract class AsyncTaskLoader<D> extends Loader<D> { private static final String TAG = "AsyncTaskLoader"; final class LoadTask extends AsyncTask<Void, Void, D> implements Runnable { Loading @@ -40,6 +40,8 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> { D result; boolean waiting; private CountDownLatch done = new CountDownLatch(1); /* Runs on a worker thread */ @Override protected D doInBackground(Void... params) { Loading @@ -50,12 +52,20 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> { /* Runs on the UI thread */ @Override protected void onPostExecute(D data) { try { AsyncTaskLoader.this.dispatchOnLoadComplete(this, data); } finally { done.countDown(); } } @Override protected void onCancelled() { try { AsyncTaskLoader.this.dispatchOnCancelled(this, result); } finally { done.countDown(); } } @Override Loading Loading @@ -209,7 +219,8 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> { /** * Locks the current thread until the loader completes the current load * operation. Returns immediately if there is no load operation running. * Should not be called from the UI thread. * Should not be called from the UI thread: calling it from the UI * thread would cause a deadlock. * <p> * Use for testing only. <b>Never</b> call this from a UI thread. */ Loading @@ -217,12 +228,9 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> { LoadTask task = mTask; if (task != null) { try { task.get(); task.done.await(); } catch (InterruptedException e) { Log.w(TAG, e); } catch (ExecutionException e) { throw new RuntimeException("An error occured while executing waitForLoader()", e.getCause()); // Ignore } } } Loading