I am tasked with displaying a random number after a 5 second delay using Thread.sleep(5000)
, on a button click using the Handler
/Looper
/Thread
/Runnable
approach rather than implementing an AsyncTask
. My problem is, I'm having issues finding examples online of how to implement this task with the aforementioned approach. So, following common HandlerThread
/Looper
related practices how would I implement this simple task that I described above?
As after thoughts (I mainly want to know about my question mentioned above right now):
- I would like to make sure that multiple clicks of the Button don't restart the process with each click (only once the 5 seconds are up).
- I would like to allow this simple task to be maintained throughout orientation changes, even if the orientation occurs midway through the 5 second delay that occurs via
Thread.sleep(5000)
After, After thought:
- The Button and TextView that display the random number exist within a fragment that my
MainActivity
calls.