As I understand it, the only difference between Thread.sleep () and SystemClock.sleep () is that Thread.sleep () can be interrupted. That is, something like:
SystemClock.sleep(10*1000);
the calling thread sleeps for 10 seconds, and you just have to wait. Pay attention to:
Thread.sleep(10*1000);
the caller will also sleep for 10 seconds. But if you have a link to a sleeping thread from another thread, now you have the option:
sleepingThread.interrupt();
which effectively wakes sleepThread from its 10 second sleep.
In the context of your question, which is best suited for AsyncTask, I think it still fully meets your requirements. Of course, I donβt know your exact code, but given your task, doInBackground seems to be sleeping a bit, and given that you want to cancel your task at any time, Thread.sleep () may make more sense.
source share