I'm writing a program to draw one circle at a time onto SurfaceView using a secondary thread. It runs fine, but I would see multiple circles at a time. Can you please help as I'm going insane trying to understand where the bug could be. Inside the class which implments Runnable, I have the run method continuously draw different circles and post to the surface one at a time (or at least I think so).
Using java Syntax Highlighting
- @Override
- public void run(){
- try {
- while(!done){
- //done is set to be false so we can continuously draw onto the SurfaceView until quitJob() is called.
- //code to change drawing_r here
- synchronized(mholder){
- c = mholder.lockCanvas();
- c.drawCircle(center.x, center.y, drawing_r, mbrush);
- mholder.unlockCanvasAndPost(c);
- }
- Thread.sleep(2000);
- }
- }catch (InterruptedException ex){}
- }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
Inside the class which extends SurfaceView, I have the following resume and pause methods which are called by SurfaceCreated and SurfaceDestroyed, respectively.
Using java Syntax Highlighting
- public void resume(){
- //start the background drawing job
- if(jobThread != null){
- pause();
- }
- job = new bckGrndJob(mholder.getSurfaceFrame().width(), mholder.getSurfaceFrame().height());
- //task
- jobThread = new Thread(job, "draw");
- jobThread.start();
- }
- public void pause(){
- //stop the thread/job
- job.quitJob(); //this will set done to be true and allows the Runnable run method above to exit the while loop
- if(jobThread != null){
- try {
- jobThread.join();
- } catch (InterruptedException e) {}
- }
- jobThread = null;
- }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
Thank you for looking.


