So when running the following method in doInBackground() inside of AsyncTask derived class:
void waitUntilButtonClicked(){
while(true){
synchronized (buttonClicked){
if(buttonClicked) return;
}
try{Thread.sleep(1);} catch(InterruptedException e){};
}
without the very last line of code which makes the background thread sleep for 1 ms, the User Interface doesn't work (there is an EditText widget which when tapped on doesn't respond at all). I should mention that when waitUntilButtonClicked() runs the UI thread doesn't run anything (or rather not any of my code).
My problem is that I HAD to add the last line for everything to work. I thought that a background thread cannot block the UI thread unless there is a huge error on the programmer's part. Why does it happen? And yes I've figured out a 'way' to overcome that, is my solution a common method of doing that? Is there a better way?