How to run a Runnable thread in Android at defined intervals?

后端 未结 11 2293
青春惊慌失措
青春惊慌失措 2020-11-22 02:50

I developed an application to display some text at defined intervals in the Android emulator screen. I am using the Handler class. Here is a snippet from my cod

11条回答
  •  生来不讨喜
    2020-11-22 03:32

    If I understand correctly the documentation of Handler.post() method:

    Causes the Runnable r to be added to the message queue. The runnable will be run on the thread to which this handler is attached.

    So examples provided by @alex2k8, even though are working correctly, are not the same. In case, where Handler.post() is used, no new threads are created. You just post Runnable to the thread with Handler to be executed by EDT. After that, EDT only executes Runnable.run(), nothing else.

    Remember: Runnable != Thread.

提交回复
热议问题