How can Android code to detect when a handler's runnable process is completed? In this particular application, no other events are generated other than the handler finishing its work.
Simply putting a while()
loop around a continuous test of a global boolean flag doesn't seem to work:
... stuff to do before the handler's runnable is started
while (globalBooleanFlagStatingThatRunnableIsNotYetFinished)
Thread.sleep(5);
... stuff to do only after the handler's runnable is finished, like process data
Using the while()
approach, it appears that execution pauses forever at the semicolon until a force close is pushed by the OS, regardless of the success of the runnable to set said boolean flag.
How have others detected the completion of a runnable process?
Your while loop hogs all the cpu time so nothing else, like UI messages, have time to be processed.
The usual fix is ti put a short
Sleep()
inside the loop. This results in a call to the kernel allowing it to run other task bits for a while.Other I/O such as console prints an file read/writes also do this.