I am programming simple game. Draw/Update go throw realtime model, so CPU is always high loaded. Thread looks so:
@Override
public void run() {
while (true) {
if (!mRun) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {};
} else {
Canvas c = null;
try {
c = mSurfaceHolder.lockCanvas(null);
synchronized (mSurfaceHolder) {
..update game objects..
if (canvas != null) {
..draw to canvas...
}
}
} finally {
if (c != null) {
mSurfaceHolder.unlockCanvasAndPost(c);
}
}
}
}
}
Problem is that working so application eats battery. On my Galaxy S2 it drains faster than charges in the same moment being on PC USB.
What am I doing wrong, or it's OK for games?