How can I give a delay of few seconds without using threads.some function that I can call anywhere for giving delay. Android built-in function is highly preferred. Thanks
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use a Handler, and send either a simple message or a Runnable to it using a method such as postDelayed().
For example, define a Handler object to receive messages and Runnables:
Define a Runnable:
Cause the Runnable to be sent to the Handler after a specified delay in
ms:If you don’t want the complexity of sending a Runnable to the Handler, you could also very simply send a message to it – even an empty message, for greatest simplicity – using method
sendEmptyMessageDelayed().