在android中一般是子线程向主线程发送消息,那主线程能否向子线程发送消息呢?答案是肯定的。
请看android文档中Looper类的一段文档:

Class used to run a message loop for a thread. Threads by default do not have a message loop associated with them; to create one, call prepare() in the thread that is to run the loop, and then loop() to have it process messages until the loop is stopped.

Most interaction with a message loop is through the Handler class.

This is a typical example of the implementation of a Looper thread, using the separation of prepare() and loop() to create an initial Handler to communicate with the Looper.

  class LooperThread extends Thread {      public Handler mHandler;            public void run() {          Looper.prepare();                    mHandler = new Handler() {              public void handleMessage(Message msg) {                  // process incoming messages here              }          };                    Looper.loop();      }  }


主线程通过子线程中定义的Handler 向子线程发送message。先写到这里吧,等周末有空再进行详细说明。

更多相关文章

  1. Android中对Handle机制的理解
  2. Android(安卓)Handler详解
  3. Android(安卓)异步加载解决方案(循环,多任务)
  4. Android的子线程能更新UI吗?
  5. Android(安卓)回炉 阿里巴巴Android开发规范
  6. android 将程序设置为app2sd
  7. Android异步加载图像小结
  8. Android中Handler源码解析(一)
  9. android 线程大集合

随机推荐

  1. 了解Android堆和栈
  2. oms和android在开发上有什么不同?
  3. android中WebView的简单使用
  4. Eclipse新建android工程报"Check Android
  5. Android如何开发自定义编译时注解
  6. Android(安卓)SDK中 tools 目录下的工具
  7. android注解使用详解(图文)
  8. Android 面试必备 - 知识图谱
  9. android 监控软键盘确定 搜索 按钮并赋予
  10. 初次体验Android,过程很艰辛!