tags:

views:

54

answers:

1

I have an Activity that contains several views. One of which is a GLSurfaceView. This GLSurfaceView displays pretty 3D effects based on what is selected in my Activity's other views (ListViews, EditTexts, etc). The issue I am having is that I don't know when my GLSurfaceView has been fully initialized from the Activity.

I began by simply attempting to pass my graphics data to my GLSurfaceView in my Activity's onCreate() method shortly after the setContentView() method. This worked fine on the emulator but on several devices this fails with null pointer exceptions from attempting to access objects that had not even been constructed yet. I assumed it was because my view had not been inflated yet and perhaps inflating views just takes longer on my devices.

I scattered some logging just to see the order of things and I found that my GLSurfaceView's onSurfaceCreated method is called well after the GLSurfaceView's onFinishInflate method.

So now I am looking for a good way to determine in my Activity when my GLSurfaceView's onSurfaceCreated method has been called so that I can safely tell my GLSurfaceView what to draw.

A: 

Subclass GLSurfaceView ("To handle an event you will typically subclass GLSurfaceView and override the appropriate method, just as you would with any other View"). You might also register a SurfaceHolder.Callback with the Surfenter code hereaceHolder -- that works with regular SurfaceViews to know when their surfaces have been created.

CommonsWare