i have an activities that host fragments. pressing a button goes from fragment A to fragment B through a FragmentTransaction and the added to the back stack. Now fragment B
Override the onStop() of your fragment and do:
protected void onStop() { super.onStop(); //check the state of the task if(task != null && task.getStatus() == Status.RUNNING) task.cancel(true); }