I’m using a SurfaceView and I have to update it as fast as I can. Since the onDraw method isn’t called automatically I have to call explicitly. So my first attempt was on threads, but I got some lag. There is a better way to do this? If there is a better solution, can you, please, explain me? I’m new on Android’s World!
What I have so far
public void run() {
while(running){
Canvas c = null;
try {
c = view.getHolder().lockCanvas();
synchronized (view.getHolder()) {
view.onDraw(c);
}
} finally {
if (c != null) {
view.getHolder().unlockCanvasAndPost(c);
}
}
}
}
Here’s my code that I use as a rendering thread. The fps is updated frame dependent. I usually run my games at 30 fps.
(There’s some code you won’t need, but I’m sire you’ll be able to find the pieces you are looking for.)
I suggest you take a look at this link or have a look at
http://code.google.com/p/beginning-android-games/
or http://www.edu4java.com/en/androidgame/androidgame3.html