surfaceCreated() never called


Last Updated:

  1. inquisition

    inquisition Member This Topic's Starter

    Joined:
    Nov 15, 2009
    Messages:
    5
    Likes Received:
    0
    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
     

    Advertisement
  2. inquisition

    inquisition Member This Topic's Starter

    Joined:
    Nov 15, 2009
    Messages:
    5
    Likes Received:
    0
    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
     
  3. Malone

    Malone New Member

    Joined:
    Mar 27, 2011
    Messages:
    1
    Likes Received:
    1
    Just got the same issue. Resolved it with
    following code in constructor:

    getHolder().addCallback(this);
     
    JG4m3r likes this.

Share This Page

Loading...