【问题标题】:Is it safe to call the View.post(runnable) method in the main thread?在主线程中调用 View.post(runnable) 方法是否安全?
【发布时间】:2016-11-22 17:15:39
【问题描述】:

我在 RecyclerView 中有一个视图。我在 onBindViewHolder() 方法中调用 myView.post(runnable) 以在布局传递完成后收集有关 myView 的信息。如果主机活动在我的可运行文件开始之前以某种方式被破坏,是否存在崩溃我的应用程序的风险?

【问题讨论】:

    标签: android android-recyclerview android-view android-viewbinder


    【解决方案1】:

    一般来说是安全的。但是,如果您的 onDestroy 释放任何资源或清空您的 Runnable 所依赖的任何变量,您可能会遇到极端情况。在大多数情况下,我不会担心它。它不能在 finalize() 之后调用,因为 Runnable 将保留对您的活动的引用,防止它在 Runnable 运行之前被垃圾收集。那将是真正的问题,但框架/语言阻止了它。

    【讨论】:

      猜你喜欢
      • 2015-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-17
      • 2018-06-30
      • 1970-01-01
      相关资源
      最近更新 更多