The thread that is blocked is the UI thread. Proving this with a debugger is a good idea. You can confirm this by viewing the source code of SurfaceView.java
(if in Eclipse, hit F3
while the cursor is on the text SurfaceView
). In particular:
The callbacks such as surfaceDestroyed()
are called from SurfaceView.updateWindow()
:
private void updateWindow(boolean force, boolean redrawNeeded) {
...
callbacks = getSurfaceCallbacks();
for (SurfaceHolder.Callback c : callbacks) {
c.surfaceDestroyed(mSurfaceHolder);
}
updateWindow()
is called from the anonymous class derived from Handler
and assigned to mHandler
:
final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case KEEP_SCREEN_ON_MSG: {
setKeepScreenOn(msg.arg1 != 0);
} break;
case GET_NEW_SURFACE_MSG: {
handleGetNewSurface();
} break;
case UPDATE_WINDOW_MSG: {
updateWindow(false, false);
} break;
}
}
};
Note that this mHandler
object is constructed when the SurfaceView
object is constructed, which happens on the UI thread. And note that the Handler
constructor binds the Handler
to the Looper
associated with the current thread (the UI thread). So handleMesssage()
runs on that Looper
which is the UI thread's Looper
. Thus, updateWindow()
is called on the UI thread.
updateWindow()
is also called several other times in the file and most of the time it is easy to deduce that it is being called from the UI thread.