Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1070113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:30:54+00:00 2026-05-16T20:30:54+00:00

I’ve been trying to make a simple live wallpaper out of a boot animation.

  • 0

I’ve been trying to make a simple live wallpaper out of a boot animation. So basically i have about 50 .pngs in my drawable folder. I’m able to set the animation to about 10-20 frames and it works great. But once i set it to about 30 frames…I get an OutOfMemory Error. I was hoping maybe someone could take a look at my code and maybe give an example of how I could achieve more frames? That would help so much i’ve been looking at this for hours > <

Here’s my code:

package com.androidnetwork.animlivewp;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.os.Handler;
import android.os.SystemClock;
import android.service.wallpaper.WallpaperService;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;

public class AnimatedLiveWallpaper extends WallpaperService {

    private final Handler mHandler = new Handler();

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public Engine onCreateEngine() {
        return new CubeEngine();
    }

    class CubeEngine extends Engine {

        private final Paint mPaint = new Paint();
        private float mPosY;
        private boolean mAnime = true;
        private Matrix mMatrix = new Matrix();

        private final Runnable mDrawAnim = new Runnable() {
            public void run() {
                drawFrame();
            }
        };
        private boolean mVisible;

        private static final int NUM_RES = 30;
        private final Bitmap[] mPics = new Bitmap[NUM_RES];
        CubeEngine() {
            Resources res = getResources();
            for (int i = 0; i< NUM_RES; i++) {
                int id = res.getIdentifier("boot_00" + (100 + (i + 1)), "drawable", "com.androidnetwork.animlivewp");
                mPics[i] = BitmapFactory.decodeResource(res, id);
            }
        }

        @Override
        public void onCreate(SurfaceHolder surfaceHolder) {
            super.onCreate(surfaceHolder);

            setTouchEventsEnabled(false);
        }

        @Override
        public void onDestroy() {
            super.onDestroy();
            mHandler.removeCallbacks(mDrawAnim);
        }

        @Override
        public void onVisibilityChanged(boolean visible) {
            mVisible = visible;
            if (visible) {
                drawFrame();
            } else {
                mHandler.removeCallbacks(mDrawAnim);
            }
        }

        @Override
        public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
            super.onSurfaceChanged(holder, format, width, height);

            float w = mPics[0].getWidth();
            float h = mPics[0].getHeight();
            float s = width / (float)w;
            mMatrix.reset();
            mMatrix.setScale(s, s);

            mPosY = (height - (h * s)) / 2f;
            drawFrame();
        }

        @Override
        public void onSurfaceCreated(SurfaceHolder holder) {
            super.onSurfaceCreated(holder);
        }

        @Override
        public void onSurfaceDestroyed(SurfaceHolder holder) {
            super.onSurfaceDestroyed(holder);
            mVisible = false;
            mHandler.removeCallbacks(mDrawAnim);
        }

        @Override
        public void onOffsetsChanged(float xOffset, float yOffset,
                float xStep, float yStep, int xPixels, int yPixels) {
            drawFrame();
        }


        @Override
        public void onTouchEvent(MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_MOVE) {
                mAnime = !mAnime;
            }
            super.onTouchEvent(event);
        }


        void drawFrame() {
            final SurfaceHolder holder = getSurfaceHolder();

            Canvas c = null;
            try {
                c = holder.lockCanvas();
                if (c != null) {
                    // draw something
                    drawAnim(c);
                    //drawTouchPoint(c);
                }
            } finally {
                if (c != null) holder.unlockCanvasAndPost(c);
            }

            // Reschedule the next redraw
            mHandler.removeCallbacks(mDrawAnim);
            if (mVisible && mAnime) {
                mHandler.postDelayed(mDrawAnim, 1000 / 10);
            }
        }


        private int idx = 0;
        void drawAnim(Canvas c) {
            c.save();
            c.translate(0, mPosY);
            c.drawBitmap(mPics[idx], mMatrix, mPaint);
            if (mAnime) ++idx;
            if (idx == NUM_RES) idx = 0;

            c.restore();
        }



    }
}

And here’s a logcat if that’ll help at all:

08-22 19:45:05.508: ERROR/AndroidRuntime(12277): FATAL EXCEPTION: main
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at android.graphics.Bitmap.nativeCreate(Native Method)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:346)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:372)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at com.androidnetwork.animlivewp.AnimatedLiveWallpaper$CubeEngine.<init>(AnimatedLiveWallpaper.java:55)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at com.androidnetwork.animlivewp.AnimatedLiveWallpaper.onCreateEngine(AnimatedLiveWallpaper.java:32)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:814)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:61)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at android.os.Handler.dispatchMessage(Handler.java:99)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at android.os.Looper.loop(Looper.java:123)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at android.app.ActivityThread.main(ActivityThread.java:4627)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at java.lang.reflect.Method.invokeNative(Native Method)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at java.lang.reflect.Method.invoke(Method.java:521)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    08-22 19:45:05.508: ERROR/AndroidRuntime(12277):     at dalvik.system.NativeStart.main(Native Method)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:30:54+00:00Added an answer on May 16, 2026 at 8:30 pm

    Only create one bitmap and reload each png each time you draw your canvas. For example create a simple routine that will reload each image into the same bitmap allocation. I would also suggest that you convert the png files into jpg files, as png are a lossless format. With jpg you can compress each frame slightly.

    public void updateBG() {
    
    idx += 1;
    if (idx == NUM_RES) {idx = 0;}
    switch (bgcycle) {
        case 0: myBg = BitmapFactory.decodeResource(getResources(),R.drawable.frame1); break;
        case 1: myBg = BitmapFactory.decodeResource(getResources(),R.drawable.frame2); break;
        case 2: myBg = BitmapFactory.decodeResource(getResources(),R.drawable.frame3); break;
                case etc....
            }}
    

    Or I guess you could use this if you want to link to the bootanimation

    int id = res.getIdentifier("boot_00" + (100 + (idx + 1)), "drawable", "com.androidnetwork.animlivewp");
                myBg = BitmapFactory.decodeResource(res, id);
    

    Then in your DrawAnim code just

    updateBG();
    c.drawBitmap(myBg, mMatrix, null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have been unable to fix a problem with Java Unicode and encoding. The
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.