Replacing View With Surfaceview To Draw On Other Than The Ui Thread
The following program does not work unless the line while (!done) (and the closing bracket) are uncommented. Do you understand why? Why is it not possible to ask the thread to run
Solution 1:
There you go
publicclassMySurfaceViewextendsSurfaceViewimplementsSurfaceHolder.Callback {
...
classMyThreadextendsThread {
booleanupdate=false;
@Overridepublicvoidrun() {
SurfaceHoldersurfaceHolder= holder;
while (!done) {
if(update) {
Canvascanvas= surfaceHolder.lockCanvas();
canvas.drawARGB(255, 0, 0, 128);
canvas.drawCircle(x, y, 5.0f, paint);
surfaceHolder.unlockCanvasAndPost(canvas);
update = false;
}
}
}
}
publicvoidrequestUpdate() {
update = true;
}
}
and whenever something is changed, just call requestUpdate();
Post a Comment for "Replacing View With Surfaceview To Draw On Other Than The Ui Thread"