// Selection handler for the embedded Gallery view
 @Override
 public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
   if (mLoader != null && mLoader.getStatus() != WallpaperLoader.Status.FINISHED) {
     mLoader.cancel();
   }
   mLoader = (WallpaperLoader) new WallpaperLoader().execute(position);
 }
  @Override
  protected void onDestroy() {
    super.onDestroy();

    if (mLoader != null && mLoader.getStatus() != WallpaperLoader.Status.FINISHED) {
      mLoader.cancel(true);
      mLoader = null;
    }
  }
 private void cancelLoader() {
   if (mLoader != null && mLoader.getStatus() != WallpaperLoader.Status.FINISHED) {
     mLoader.cancel(true);
     mLoader = null;
   }
 }