更新游戏画面时线程的问题
作者daytodayme
http://www.iteye.com/topic/435147
调用Handler.post(Runnable r)方法,Runnable运行在UI所在线程,所以可以直接调用View.invalidate()
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); myView = new MyView(this); this.setContentView(this.myView); new Thread(new myThread()).start(); } class myThread implements Runnable { public void run() { while (!Thread.currentThread().isInterrupted()) { try { myView.postInvalidate(); Thread.sleep(100); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } }