// 在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