【问题标题】:Is it necessary to call Looper.prepare() from within the UI thread?是否有必要从 UI 线程中调用 Looper.prepare() ?
【发布时间】:2012-03-10 07:29:45
【问题描述】:

如果我想在 Activity 的主线程中实现一个 Handler 对象,我需要事先调用 Looper.prepare(),还是 Activity 已经有自己的内部 Looper?如果我想从 Service 中实例化 Handler 实例,同样适用吗?

【问题讨论】:

    标签: android android-activity handler looper


    【解决方案1】:

    主线程已经有了自己的looper。见Context.getMainLooper()。主线程包含应用程序中的所有活动和服务。

    【讨论】:

      猜你喜欢
      • 2017-04-21
      • 1970-01-01
      • 2016-11-09
      • 2016-09-05
      • 1970-01-01
      • 2012-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多