am 5f404299: am aa3687df: am 2e5555e0: Bitmapfun Sample: Fix bug where background image loading could hang
# Via Android Git Automerger (2) and Adam Koch (1)
* commit '5f4042990ac33bd05cd4e3f48935d6eb0dc552c9':
Bitmapfun Sample: Fix bug where background image loading could hang
diff --git a/samples/training/bitmapfun/src/com/example/android/bitmapfun/ui/ImageGridFragment.java b/samples/training/bitmapfun/src/com/example/android/bitmapfun/ui/ImageGridFragment.java
index fb18d07..dabee2d 100644
--- a/samples/training/bitmapfun/src/com/example/android/bitmapfun/ui/ImageGridFragment.java
+++ b/samples/training/bitmapfun/src/com/example/android/bitmapfun/ui/ImageGridFragment.java
@@ -149,6 +149,7 @@
@Override
public void onPause() {
super.onPause();
+ mImageFetcher.setPauseWork(false);
mImageFetcher.setExitTasksEarly(true);
mImageFetcher.flushCache();
}
diff --git a/samples/training/bitmapfun/src/com/example/android/bitmapfun/util/ImageWorker.java b/samples/training/bitmapfun/src/com/example/android/bitmapfun/util/ImageWorker.java
index 32c43b2..0f890e0 100644
--- a/samples/training/bitmapfun/src/com/example/android/bitmapfun/util/ImageWorker.java
+++ b/samples/training/bitmapfun/src/com/example/android/bitmapfun/util/ImageWorker.java
@@ -150,6 +150,7 @@
public void setExitTasksEarly(boolean exitTasksEarly) {
mExitTasksEarly = exitTasksEarly;
+ setPauseWork(false);
}
/**
@@ -372,6 +373,18 @@
}
}
+ /**
+ * Pause any ongoing background work. This can be used as a temporary
+ * measure to improve performance. For example background work could
+ * be paused when a ListView or GridView is being scrolled using a
+ * {@link android.widget.AbsListView.OnScrollListener} to keep
+ * scrolling smooth.
+ * <p>
+ * If work is paused, be sure setPauseWork(false) is called again
+ * before your fragment or activity is destroyed (for example during
+ * {@link android.app.Activity#onPause()}), or there is a risk the
+ * background thread will never finish.
+ */
public void setPauseWork(boolean pauseWork) {
synchronized (mPauseWorkLock) {
mPauseWork = pauseWork;