普通打印线程 和 修改UI界面的线程 一个运行成功 一个异常
public class MainActivity extends ActionBarActivity { private Button start_btn = null; private MyThread mythread =null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); start_btn =(Button)findViewById(R.id.startbtn); start_btn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub mythread = new MyThread(); mythread.start(); } }); } public void display(){ Toast.makeText(getApplicationContext(), "this", Toast.LENGTH_SHORT).show(); } public class MyThread extends Thread{ public void run(){ Log.d("tedt", "aa"); MainActivity.this.display(); } } }
所以,线程的使用必须注意UI界面的问题