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
Canceling the AsyncTask in onStop() is not a very good choice because it can stop the AsyncTask in scenarios where you would want it to keep running. Imagine you have a fragment/activity where you show several images downloaded from the net and tapping an image is supposed to take the user to another image specific app. This would make your fragment hit onStop() and cancel your AsyncTask even though there may still be images you want to download for when the user comes back to the activity. I think doing it in onDestroy() is a better choice.
@Override
public void onDestroy() {
super.onDestroy();
if(doTask != null){
doTask.cancel(true);
}
}