当前位置:   article > 正文

停止在Android视图中使用Post / PostDelayed

android view取消post

Since its beginning, Android has provided a Handler API. As the documentation states, it allows you to deliver messages from a queue on a Looper’s thread.

从一开始,Android就提供了Handler API。 如文档所述,它允许您从Looper线程上的队列传递消息。

  1. Handler().postDelayed({
  2. doSomething()}, delay)

This API is handy and yet so sneaky. Don’t let yourself be fooled when using it on a view. To understand where the danger lies, we need to dig deeper into the View class.

这个API很方便,但是却很偷偷摸摸。 在视图上使用它时,不要让自己上当。 要了解危险所在,我们需要更深入地研究View类。

视图处理程序 (Handlers for Views)

View in Android leverages the Handler API. It acts as a passthrough with an inner Handler and exposes both post() and postDelayed() functions.

Android中的View利用Handler API。 它充当内部Handler postDelayed()并公开post()postDelayed()函数。

Have a closer look at its implementation (at the time I’m writing the article):

仔细研究其实现(在撰写本文时):

  1. /**
  2. * <p>Causes the Runnable to be added to the message queue, to be run
  3. * after the specified amount of time elapses.
  4. * The runnable will be run on the user interface thread.</p>
  5. *
  6. * @param action The Runnable that will be executed.
  7. *
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/240662?site
推荐阅读
相关标签
  

闽ICP备14008679号