Three methods of Android delay operation

In Android development, we may need to delay the execution of an operation. For example, when we start the application, we first present the guidance page and enter the main interface after 3 seconds. This is a delayed operation.

Here are three methods to realize delay operation:

1、 Use thread sleep to implement delayed operation

2、 Delaying operation using TimerTask

3、 Use the handler's postdelayed () method to implement the delayed operation

Note: if the first two methods do not use the message processing mechanism when updating the UI, the following exception will be reported: only the original thread that created a view hierarchy can touch its views. In order to avoid this error, the third method is recommended when using the delayed operation.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>