I just wrote a simple Android app that uses SurfaceHolder.Callback interface to communicate the state of the SurfaceView. In the Callback.surfaceDestroyed() method i just informed the rendering thread to terminate and returned, like so:
public void surfaceDestroyed(SurfaceHolder holder) {
renderingThread.requestStop();
}
I did this because in the Android documentation SurfaceHolder.lockCanvas() it states that a null will be returned when the surface is not available. And also that the SurfaceHolder holds a lock internally until SufraceHolder.unloackCanvasAndPost() is called, which prevents calls to SurfaceHolder.Callback methods.
So to me it seems that it's not necessary to wait for the rendering thread to finish. However all examples I've seen wait for the thread to finish, usually something like:
public void surfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
rederingThread.setRunning(false);
while (retry) {
try {
thread.join();
retry = false;
} catch (InterruptedException e) {
}
}
}
Is this really necessary? My application runs without problems.