package com.test;import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;public class HandlerTest extends Activity {
    /** Called when the activity is first created. */
    private Handler handler = new Handler();
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        handler.post(r);
        setContentView(R.layout.main);
        System.out.println("Activity----"+Thread.currentThread().getId());
        System.out.println("Activity----"+Thread.currentThread().getName());
     }
     Runnable r = new Runnable(){ @Override
public void run() {
System.out.println("Handler----"+Thread.currentThread().getId());
System.out.println("Handler----"+Thread.currentThread().getName());
try{
Thread.sleep(10000);
}catch(InterruptedException e){
e.printStackTrace();
}
}
    
    };
}

解决方案 »

  1.   

    在setContentView前后post,handler都不打log么?
      

  2.   

    handler 发message是可以收到的。
      

  3.   

     handler.post(r);只是把Runnable放到主线程的消息队列里,消息队列的处理是按照先进先出的顺序的,并不是马上执行。
      

  4.   

    首先import相关的类
    然后定义public static final String TAG =  HandlerTest 
    可以log.d(TAG,"");
    一般在android下是这么用的,可以然后在打印的时候只打印你相关应用程序的log.