我现在正在关注 thenewboston 的教程。我一直在 while 循环中遇到无法访问代码的错误,即不断检查持有者是否为真。
编辑这已经解决了。
SurfaceHolder ourHolder;
Thread ourThread = null;
boolean isRunning = true;
public MyBringBackSurface(Context context) {
super(context);
ourHolder = getHolder();
ourThread = new Thread(this);
ourThread.start();
}
public void pause(){
isRunning = false;
while(true){
try {
ourThread.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
ourThread = null;
}
public void resume(){
isRunning = true;
ourThread = new Thread(this);
ourThread.start();
}
@Override
public void run() {
// TODO Auto-generated method stub
while(isRunning){
if(!ourHolder.getSurface().isValid());
continue;
Canvas canvas = ourHolder.lockCanvas(); //Unreachable code
canvas.drawRGB(02, 02, 150);
ourHolder.unlockCanvasAndPost(canvas);
}
}
}