I think because if we would use a bool the tasks in queue that are left over will not be able to execute. For example if we have 3 tasks in queue and set the bool to false those leftover tasks will not execute. In this way we put the poison task at the end of the queue, so when all tasks get finished only then will the Looper finish looping.
Thank you for the great explanation 🙏 Amazing work
Great explanation!
Very nice explanation... thank you
Hi. Great explanation... I have one question, why we not use boolean variable to break while loop instead of poison object?
I think because if we would use a bool the tasks in queue that are left over will not be able to execute. For example if we have 3 tasks in queue and set the bool to false those leftover tasks will not execute. In this way we put the poison task at the end of the queue, so when all tasks get finished only then will the Looper finish looping.