How do I make Java wait for a method to finish before continuing?

前端 未结 2 1935
不思量自难忘°
不思量自难忘° 2021-01-21 09:24

So my problem is that I need these methods to run one after another but I cannot work out how to make the methods wait before being run. Any help is appreciated. Thank you. Here

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-21 09:51

    You can use Thread.sleep(timeInMiliseconds) to pause the currently executing thread. If this is the same thread you use to update your UI then the UI will be frozen during the sleep so it's best to keep all the UI stuff on its own thread.

提交回复
热议问题