Looper.getMainLooper()究竟怎么用啊

现在想在子线程中发消息给主线程来操作主线程ui,子线程的发送消息代码如下:

 public void MsgToMainMainInterface(int msg,Object obj){
        if(msg==MSG.mShowData.mString){
        Message m=Message.obtain();
        m.what=MSG.mShowData.mString;
        m.obj=obj;
        MainHandler=new Handler(Looper.getMainLooper());
        MainHandler.sendMessage(m);
        }

这是主UI MainInterface的handler

  mainHandler=new Handler(){
                public void handleMessage (Message msg) {
                    System.out.println(msg.what);
                    switch(msg.what){
                    case MSG.mShowData.mString:
                        TextView textView2=(TextView)findViewById(R.id.textView2);
                        textView2.setText((String)msg.obj);
                        break;  
                    default:

                    }
                }
            };

但是完全没反应

但是有个方法可以:
先把MainInterface中的MainHandler变成静态的。

 public void MsgToMainMainInterface(int msg,Object obj){
        if(msg==MSG.mShowData.mString){
        Message m=Message.obtain();
        m.what=MSG.mShowData.mString;
        m.obj=obj;
    _   MainInterface.MainHandler.sendMessage(m);_
        }

这样就可以了

为什么用 MainHandler=new Handler(Looper.getMainLooper());不能获取ui中的handler啊

你的handler在哪创建的,你根本不需要getMainLooper,只需要把UI线程中创建的handler传递给子线程即可

直接用同一个嘛,不用从新实例化一个