@Override public void finish() { // if they try and enter a password and hit cancel, GTGActivityHelper has no choice but to back // up through all the activities on the stack // so we have to cancel the restore, because our activity is about to finished. // Note that using singleTask doesn't help here because we are finishing the task regardless. if (backupTask != null) backupTask.cancel(); backupTask = null; super.finish(); }
/** * Stop task. If it is in task manager then it will be removed from the TaskManager, all the * TaskListeners assigned to this Task will also be deleted. all the property change listeners * assigned to thia task will be deleted * * @param task task * @param interrupt whether to notify * @return boolean true is the cancel has been finished. */ @SuppressWarnings("unchecked") public boolean cancelTask(Task task, boolean interrupt) { boolean canceled = false; // remove task from task manager boolean hasTask = hasTask(task); if (hasTask) { // cancel all the children tasks first cancelTasksByOwner(task); List<Task> oldTasks, newTasks; synchronized (tasks) { oldTasks = new ArrayList<Task>(tasks); tasks.remove(task); canceled = task.cancel(interrupt); newTasks = new ArrayList<Task>(tasks); task.removePropertyChangeListener(taskPropListener); } firePropertyChange(REMOVE_TASK_PROP, oldTasks, newTasks); } return canceled; }
private void cancelTask() { if (task == null) { return; } Log.d(TAG, "Cancel Task " + task.cancel(true)); }
/** Invoked when the user presses the start button. */ public void actionPerformed(ActionEvent evt) { if (evt.getActionCommand().equals("start")) { StartButton.setEnabled(false); cancelButton.setEnabled(true); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); // Instances of javax.swing.SwingWorker are not reusuable, so // we create new instances as needed. DownloadMessage theMessage = new DownloadMessage() { public void setProgress(int Progress) { if (myState.equals("SPLIT")) { progressBar.setValue(Progress); } else if (myState.equals("DOWNLOADREMOTE")) { progressBar.setValue(Progress); } else if (myState.equals("DOWNLOADLOCALBASE")) { progressBar3.setValue(Progress); } else if (myState.equals("TOTAL")) { progressBar4.setValue(Progress); progressBar3.setValue(0); progressBar2.setValue(0); progressBar.setValue(0); } } public void messageChanged(int Progress, String message) { setProgress(Progress); taskOutput.append(message + "\n"); taskOutput.setCaretPosition(taskOutput.getDocument().getLength()); // TODO Auto-generated method stub } public void stateChanged(String theState) { myState = theState; // TODO Auto-generated method stub } public void messageChanged(String theMessage) { taskOutput.append(theMessage + "\n"); taskOutput.setCaretPosition(taskOutput.getDocument().getLength()); // TODO Auto-generated method stub // TODO Auto-generated method stub } }; task = new Task(theMessage, (String) myDownloadOptions.getSelectedItem()); task.addPropertyChangeListener(this); task.execute(); } else if (evt.getActionCommand().equals("cancel")) { task.cancel(false); // startButton.setEnabled(true); // cancelButton.setEnabled(false); } }