am 2e5555e0: Bitmapfun Sample: Fix bug where background image loading could hang

# Via Adam Koch
* commit '2e5555e04b1e78f2d6fc48e8069b33399a4cf028':
  Bitmapfun Sample: Fix bug where background image loading could hang
This commit is contained in:
Adam Koch
2013-02-01 13:27:32 -08:00
committed by Android Git Automerger
2 changed files with 14 additions and 0 deletions

View File

@@ -149,6 +149,7 @@ public class ImageGridFragment extends Fragment implements AdapterView.OnItemCli
@Override
public void onPause() {
super.onPause();
mImageFetcher.setPauseWork(false);
mImageFetcher.setExitTasksEarly(true);
mImageFetcher.flushCache();
}

View File

@@ -150,6 +150,7 @@ public abstract class ImageWorker {
public void setExitTasksEarly(boolean exitTasksEarly) {
mExitTasksEarly = exitTasksEarly;
setPauseWork(false);
}
/**
@@ -372,6 +373,18 @@ public abstract class ImageWorker {
}
}
/**
* 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;