• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps surfaceCreated() never called

Hello,

I am having a bit of trouble with what should be a simple bit of code, a lightweight drawing engine using SurfaceView. At the moment my engine instantiates a second class, GameView, which extends SurfaceView and implements SurfaceHolder.Callback. In the constructor for this class I call getHolder(), pass the resulting object's .callback 'this', and set the view as focusable. Everything goes swimmingly until I get to surfaceCreated(), it just never gets called. It seems to me like there should be another call to set the surface viewable but this is the procedure the Dev guides (and several individual tutorials) have outlined.

Has anybody had similar troubles? I know I must be missing something simple but I cannot for the life of me figure out what it is. All sources reside in the same package and are instantiated in the same activity (which just has a button to create the engine and so on).

References:
Graphics | Android Developers
Blorb Development Blog - Simple Java Android Game Loop
Playing with graphics in Android
 
So,

I figured out what the problem was. Basically, I had my view class instantiated safely away in my top level engine class. This was causing some strange scope issues when I tried to call setContentView() thus never creating the view. In the end I made a quick access method in my game class to get at the underlying view. Unfortunately, this method seems kinda hackish. Does anyone know of a better way to do this while still maintaining complete encapsulation of my engine?

-cheers
 
Back
Top Bottom