我正在使用SurfaceView做一个非常标准的绘图。 代码在大多数设备上运行平稳~60fps。但是 - 在Android 5上,我的表现非常糟糕。
有什么线索?
class MySurfaceView extends SurfaceView implements Runnable{
Thread thread = null;
SurfaceHolder surfaceHolder;
volatile boolean running = false;
public MySurfaceView(Context context) {
super(context);
surfaceHolder = getHolder();
}
public void onResumeMySurfaceView(){
running = true;
thread = new Thread(this);
thread.start();
}
public void onPauseMySurfaceView(){
boolean retry = true;
running = false;
while(retry){
try {
thread.join();
retry = false;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public void run() {
while(running){
if(surfaceHolder.getSurface().isValid()){
Canvas canvas = surfaceHolder.lockCanvas();
// drawing
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}