// 在onCreate()中開啓線程安全
}post
2,使用postInvalidate()刷新界面
使用postInvalidate則比較簡單,不須要handler,直接在線程中調用postInvalidate便可。
class GameThread implements Runnable {
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
// 使用postInvalidate能夠直接在線程中更新界面
mGameView.postInvalidate();
}
}
}this