@Test public void testCancel() { ParseFile file = new ParseFile(new ParseFile.State.Builder().build()); TaskQueueTestHelper queueHelper = new TaskQueueTestHelper(file.taskQueue); queueHelper.enqueue(); List<Task<Void>> saveTasks = Arrays.asList( file.saveInBackground(), file.saveInBackground(), file.saveInBackground()); List<Task<byte[]>> getDataTasks = Arrays.asList( file.getDataInBackground(), file.getDataInBackground(), file.getDataInBackground()); file.cancel(); queueHelper.dequeue(); for (int i = 0; i < saveTasks.size(); i++) { assertTrue("Task #" + i + " was not cancelled", saveTasks.get(i).isCancelled()); } for (int i = 0; i < getDataTasks.size(); i++) { assertTrue("Task #" + i + " was not cancelled", getDataTasks.get(i).isCancelled()); } }
@Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); // AdapterViews tend to try and avoid calling this, instead preferring to recycle the Views + // subviews. This is, however, called when the AdapterView itself is detached, or the Activity // is destroyed. if (this.file != null) { this.file.cancel(); } }
/** * Sets the remote file on Parse's server that stores the image. * * @param file * The remote file on Parse's server. */ public void setParseFile(ParseFile file) { if (this.file != null) { this.file.cancel(); } this.isLoaded = false; this.file = file; this.setImageDrawable(this.placeholder); }