My view is a bunch of normal widget and a surfaceview. I don't know why after I get surfaceholder
of SurfaceView and use getSurface()
again on holder, I will always return null.
Here is my example code :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view);
}
@Override
public void onResume() {
super.onResume();
surface = (SurfaceView) findViewById(R.id.surfaceView);
this.holder = surface.getHolder();
if (holder.getSurface().isValid()){ // get surface again
Log.i("Notice","Surface holder is valid");
}
else
Log.i("Notice","Surface holder ISNOT valid"); //Always receive this
}
When I see Android document for getSurface()
method. This is how it say:
Direct access to the surface object. The Surface may not always be available -- for example when using a SurfaceView the holder's Surface is not created until the view has been attached to the window manager and performed a layout in order to determine the dimensions and screen position of the Surface. You will thus usually need to implement Callback.surfaceCreated to find out when the Surface is available for use.
I don't understand this so much but I know I have miss something. Please explain for me, and tell me about Callback.surfaceCreated
means, and how to implement it ?
Thanks :)