handler.post&&handler.postDelayed(Runable,3000);

package com.tutor.thread;  
import android.app.Activity;  
import android.os.Bundle;  
import android.os.Handler;  
import android.util.Log;  
public class ThreadDemo extends Activity {  
    private static final String TAG = "ThreadDemo";  
    private int count = 0;  
    private Handler mHandler =  new Handler();  
      
    private Runnable mRunnable = new Runnable() {  
          
        public void run() {  
            //为了方便 查看,我们用Log打印出来  
            Log.e(TAG, Thread.currentThread().getName() + " " +count);  
            count++;  
            setTitle("" +count);  
            //每2秒执行一次  
            mHandler.postDelayed(mRunnable, 2000);  
        }  
          
    };  
    @Override 
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);   
        //通过Handler启动线程  
        mHandler.post(mRunnable);  
    }  
      
    @Override 
    protected void onDestroy() {  
        //将线程销毁掉  
        mHandler.removeCallbacks(mRunnable);  
        super.onDestroy();  
    }  

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Android_Tutor/archive/2010/08/24/5834246.aspx

你可能感兴趣的:(thread,android,.net,Blog,OS)