1、Can't create handler inside thread that has not called Looper.prepare()
问题描述:在主MainActivity中创建了Handler mHandler,然后在线程中引用这个对象,发现mHandler.sendEmptyMessage()没有问题,但是调用
Message msg = new Message(); Bundle bundle = new Bundle(); bundle.putSerializable("BANG_OBJECT",obj); msg.what = SERVER_BACK; msg.setData(bundle); mHandler.dispatchMessage(msg);报如上异常,试过在MainActitiy创建的时候new Handler(Looper.getMainLooper()){},new Handler(getApplicationContext.getMainLooper())都不行,最后解决方法:在用Looper.prepare(),Looper.loop()将mHandler.dispatchMessage(msg);包起来就可以了。