Android SurfaceView在完成活动并终止线程后仍会消耗内存。每次重新开始游戏(关闭和打开)时内存使用量都会增加。无法弄明白:( 表面破坏方法:
@Override
public void surfaceDestroyed(SurfaceHolder holder){
holder.lockCanvas();
thread.setRunning(false);
thread.join();
retry = false;
thread=null;
}
}
表面创建:
@Override
public void surfaceCreated(SurfaceHolder holder)
{
thread = new MainThread(getHolder(), this);
thread.setRunning(true);
if(thread.getState() == Thread.State.NEW)
thread.start();
}
此方法完成活动:
private void restart()
{
thread = new MainThread(getHolder(), this);
thread.setRunning(false);
thread=null;
((Activity) getContext()).finish();
}