if (isCancelled())//Выполняется return false; //Не выполняется. Вверху false publishProgress(values); //Не выполняется (почему?) return true; //Выполняется 

Just jumps over the function. It also set the breakpoints, silence


  boolean b = isCancelled(); if (b) return false; publishProgress(values); return true; 

Remade so here it is generally interesting. b initialized to true and the condition jumps to return true


Deleted the application from the phone. In the studio I did a build clean build rebuild`. Same

  • Something is wrong here. b инициализируется как true did you see that in the debugger? - iksuy
  • @iksuy yes, the condition must be true and must return false - Herrgott
  • isCancelled() , values what is there? What is onProgressUpdate ? - VAndrJ
  • "must be" or did you see it clearly? The program performs exactly what you tell it; nothing supernatural will exist. you don't say if(true) you have a variable there that gets the value from isCancelled . There is clearly something wrong. - iksuy
  • one
    Maybe you changed the code, but did not compile (or did not restart the application), you have the old version of the .class files, respectively, the porridge debugger turns out. Try to close the emulator, rebuild the project with the cleaning of the old version and see what happens. - iksuy

2 answers 2

This is a debugger / compiler / optimizer glitch, breakpoints on lines with return buggy and often jump to the last return . Unfortunately nothing can be done about it.

  • Wow ... Do java also debug problems? - Qwertiy
  • Well, I would not call this problem very unpleasant, and I have not seen any other debugging problems. - xkor

Found an error in short. Very strange somehow. The fact is that I initialized the Asynctask object and in the onCreate activity method.
In the onStart method, onStart made myAsyncTask.cancel(false); (This is what makes isCancelled() true ),
And in the onStop() myAsyncTask.cancel(true) .
Just removed the onStart method onStart with myAsyncTask.cancel(false); and everything became normal, but the onCancelled() method is called anyway, judging by the logs. Something I namudril, and yes even java tupit, here and all this was superimposed on each other. Thanks to everyone who helped.


Plus I had to cheat and check isCancelled() the following way:

 boolean ret; int choice = (isCancelled()) ? 1 : 0; if (choice == 0) { publishProgress(values); ret = true; } else ret = false; return ret;