1

my live wallpaper doesn't slide smoothly most of the time on home screen change. there is not a complicate coding for the position of background. it just use the xpixles that located on the onoffsetschanged method to adjust the x position of the wallpaper. sometime it slide well same as in the sun rise live wallpaper app. but most of the other time it slide.. dunno how to describe it but its like a static sharp move. is there any idea about that guys. best regards.

private void drawS() {
        final SurfaceHolder holder = getSurfaceHolder();        
        canvas = null;
        try {
            canvas = holder.lockCanvas();

            if (canvas != null) {

                background = BitmapFactory.decodeResource(getResources(),
                        R.drawable.background);         
                canvas.drawBitmap(background, mXPixels, mYPixels, null);

            }

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


        handler.removeCallbacks(runnableS);

        if (visible) {

            handler.postDelayed(runnableS, 25);
        }
    }
Ali
  • 9
  • 1
  • 3

2 Answers2

2

try to avoid resource creation in draw routine; remove this from drawS() function:

background = BitmapFactory.decodeResource(getResources(),
                    R.drawable.background);      

and put it wherever you initialize your stuff and just use reference to background Bitmap later on.

If you take a look at logcat you'll see that there's a lot or resource shuffling and memory management going on (allocating memory for your resource, decoding bitmap image in it etc) every time you call your drawS(); ie every time you draw your background...

Cheers,

Ivica

Ivica
  • 366
  • 1
  • 5
0

I encountered the same problem and solved by following Ivica suggestion. I moved the bitmap creation line inside the surface creation sub:

public void onSurfaceCreated(SurfaceHolder holder) {
   super.onSurfaceCreated(holder);
   mybackground = BitmapFactory.decodeResource(getResources(), R.drawable.mybg);
 }

In this way the sliding is very fluent

Vincent
  • 53
  • 11