Android Handler(Looper.getMainLooper()),Kotlin
private class MsgHandler : Handler(Looper.getMainLooper()) {private val WHAT = 0xa01override fun handleMessage(msg: Message) {if (msg.what == WHAT) {}}}
Android计时器TimerTask,Timer,Handler_android timer和timertask计时-CSDN博客文章浏览阅读1.6w次,点赞3次,收藏4次。Android计时器TimerTask,Timer,若要在TimerTask中更新主线程UI,鉴于Android编程模型不允许在非主线程中更新主线程UI,因此需要结合Android的Handler实现在Java的TimerTask中更新主线程UI。现给出一个简单示例。代码使用标准Java的TimerTask和Timer启动一个计时器Task。该任务每隔2秒更新主线程的UI(在主线程的TextV_android timer和timertask计时https://blog.csdn.net/zhangphil/article/details/43908499Can‘t create handler inside thread Thread*** that has not called Looper.prepare()_can't create handler inside thread that has not ca-CSDN博客文章浏览阅读1.8k次。文章讲述了在Android中如何避免在非主线程中直接创建Handler引发的RuntimeException,强调了Looper.prepare()和Looper.loop()的重要性。作者提供了在普通Java线程中使用Handler发送和接收消息的示例。https://blog.csdn.net/zhangphil/article/details/134165048