Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Android - SurfaceView flickers - Double Buffering

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    53
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Android - SurfaceView flickers - Double Buffering

    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.


  2. #2
    Member
    Join Date
    Oct 2011
    Posts
    53
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Android - SurfaceView flickers - Double Buffering

    Is there anyone who can help me?

  3. #3
    Member
    Join Date
    Oct 2011
    Posts
    53
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Android - SurfaceView flickers - Double Buffering

    Not even someone who could give some suggestions?

Similar Threads

  1. Android Development
    By bgroenks96 in forum Java ME (Mobile Edition)
    Replies: 3
    Last Post: August 30th, 2013, 10:03 PM
  2. Add and manage a layer over a canvas using SurfaceView
    By Nesh108 in forum Android Development
    Replies: 1
    Last Post: February 20th, 2012, 12:12 PM
  3. Help With Double Buffering/Animations
    By bgroenks96 in forum Java Theory & Questions
    Replies: 1
    Last Post: July 18th, 2011, 06:58 PM
  4. [SOLVED] Read double from console without having to read a string and converting it to double.
    By Lord Voldemort in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: June 26th, 2011, 08:08 AM
  5. Double Buffering
    By Ganezan in forum Java Theory & Questions
    Replies: 2
    Last Post: November 20th, 2009, 03:51 AM