AndroidStudio 线程

来源:互联网 发布:可以打电话的软件 编辑:程序博客网 时间:2024/06/10 11:57
package com.example.sofia.testactivityactive;


import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;


public class MainActivity extends AppCompatActivity {
    MyThread thread = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        //启动线程
        thread = new MyThread();
        thread.start();
    }


    //线程处理类 Thread  **************************************
    public class MyThread extends Thread {


        @Override
        public void run() {
            int iCount = 0;
            while( true ){
                try {
                    Thread.sleep(1000);//1秒
                    iCount++;
                    Log.e( "Thread Aread", "CurrentThread id:---->" + Thread.currentThread().getId() + Thread.currentThread().getName() + " Times:" + iCount  );


                } catch (InterruptedException e)
                {
                    e.printStackTrace();
                }
            }//while
        }//run
    }//MyThread
}
原创粉丝点击