为什么getHandler()返回null? [英] Why getHandler() returns null?

查看:3585
本文介绍了为什么getHandler()返回null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题。我溺水的MapView的路线在不同的线程是这样的:

I have got following problem. I'm drawning route on mapview in separate thread like this:

 public void drawRoute(final MapView mapView) { 
          new Thread(new Runnable() {
          public void run() {
          try {
           //Do something useful
          } catch (SomeException se) {
           Handler handler = mapView.getHandler();
           handler.post(/*show error in UI thread*/)
          }}
        }).start();
      }

但是,当我得到处理它返回null,虽然在调试模式下处理器返回并显示错误消息。可问题是什么?

But when I get handler it returns null, although in debug mode handler returned and error message is displayed. What can the problem be?

PS可能是不正确的方式得到处理程序,但我找不到有关它的信息。

PS May be it's incorrect way to get Handler, but I couldn't find information about it.

推荐答案

getHandler 方法的返回值,因为观点并没有附:

The getHandler method returns null because the view is not attached:

public Handler getHandler() {
    if (mAttachInfo != null) {
        return mAttachInfo.mHandler;
    }
    return null;
}

mAttachInfo dispatchAttachedToWindow 设置和调零的 dispatchDetachedFromWindow

而不是 mapView.getHandler()的。后()您可以直接使用的 mapView.post() (这似乎是使用 getHandler()后() ViewRootImpl.getRunQueue()后())。

Instead of mapView.getHandler().post() you can use directly mapView.post() (which seems to use getHandler().post() or ViewRootImpl.getRunQueue().post()).

这篇关于为什么getHandler()返回null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆