I have been experiencing this issue for quite a while and even after googling a while, I havent found a reasonable solution for my problem.
The issue I am experiencing is that the SurfaceView I am using flickers. Once in a while, the objects I draw flicker and they change their size or colour.
It looks like that sometimes the application skips my calls to 'Paint.setColor()' and the one to 'Paint.setStrokeWidth()'.
I have made methods which change the used paint and then, in order to try to fix this issue, to set it back to the default paint values. Still the issue persists. I have also read that the problem might be due to the double buffering. Is it the case? I am using this code for the DrawingThread:
PS. u can notice that I also tried to use a dirty Rectangle to try to see if the issue can be fixed, but still nothing. [I might not have understood what it actually does.
class DrawingThread extends Thread { private SurfaceHolder _surfaceHolder; private CustomView _cv; private boolean _run = false; public DrawingThread(SurfaceHolder surfaceHolder, CustomView cv) { super(); _surfaceHolder = surfaceHolder; _cv = cv; } public void setRunning(boolean run) { _run = run; } public boolean isRunning() { return _run; } public SurfaceHolder getSurfaceHolder() { return _surfaceHolder; } @Override public void run() { Canvas c; while (_run) { c = null; try { //c = _surfaceHolder.lockCanvas(new Rect(lon - range, lon + range, lat - range, lat + range)); c = _surfaceHolder.lockCanvas(); synchronized (_surfaceHolder) { _cv.onDraw(c); } } finally { if (c != null) { _surfaceHolder.unlockCanvasAndPost(c); } } } } }
PS. I have read somewhere I should draw on a single bitmap and then draw the bitmap on the canvas. I have tried several times but I cannot manage to do so.
Thanks in advance,
N.