1. Download our Official Android App: Forums for Android!

Apps surfaceCreated() never called

Discussion in 'Android Development' started by inquisition, Nov 24, 2009.

  1. inquisition

    inquisition Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Nov 15, 2009

    Nov 15, 2009
    5
    0
    5
    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 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Nov 15, 2009

    Nov 15, 2009
    5
    0
    5
    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 Lurker
    Rank:
    None
    Points:
    6
    Posts:
    1
    Joined:
    Mar 27, 2011

    Mar 27, 2011
    1
    1
    6
    Just got the same issue. Resolved it with
    following code in constructor:

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

Share This Page

Loading...