Thread类 — 线程简单演示
public class MainActivity extends AppCompatActivity{
@Override
protected void onCreate(Bundle saveInstanceState){
super.onCreate(saveInstanceState);
//setContentView(R.layout.activity_main);
System.out.println("1.main thread...");
//创建并启动一个子线程
Thread thread = new Thread(new Runnable(){
@Override
public void run(){
//...
try{
System.out.println("2.sub thread...");
Thread.sleep(2000);
System.out.println("3.sub thread...");
}catech(InterruptedException e){
e.printStackTrace();
}
}
});
thread.start();
System.out.println("4.main thread...");
}
}// 输出顺序为 1 4 2 3