I'm just trying to figure out the best approach for running a scolling background on an android device. The method I have so far.... its pretty laggy. I use threads, which I believe is not the best bet for android platforms

    @Override
    	public void run() {
    		// Game Loop
    		while(runningThread){
    			//Scroll background down
    			bgY += 1;
    
    			try {
    				this.postInvalidate();
    				t.sleep(10);
    			} catch (Exception e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    		}
    		
    	}

where postinvalidate in the onDraw function simply pushings the background image down

    canvas.drawBitmap(backgroundImage, bgX, bgY, null);

Thanks in advance


-----------------
**UPDATE**

I've identified the problem. And it is the fact that my player updates the same rate as the background scrolls (making it look choppy). from top to bottom. This is because both get drawn in the same function. I'm not really sure how to tackle this and would be grateful for any help. i.e so that player movement is handled separately from the map scrolling

Also how can I control the speed at which onDraw(canvas) get called?

Thanks in advance.

However, I have patched together a different run loop for anyone having the same problem. This is partially from the jetboy example on google.

Below is my inner class in my surfaceview

    class MapThread extends Thread{
        private Map map;
        private SurfaceHolder holder;
        private boolean run = false;
        
        public MapThread(Map map, SurfaceHolder holder){
            this.holder = holder;
            this.map = map;
            setRunning(true);
        }
        
        public void setRunning(boolean run){
            this.run = run;
        }
        
        @Override
        public void run(){
            while(run){
                try{
                    Canvas c = null;

                     try {
                           c = holder.lockCanvas(null);
                           synchronized (holder) {
                                map.onDraw(c);
                         }
                     } finally {

                         if (c != null) {
                             holder.unlockCanvasAndPost(c);
                         }
                     }
            }
        }
    }