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

  • SEARCH
  • Home
  • 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 7991111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:12:08+00:00 2026-06-04T13:12:08+00:00

I’m stuck. I’m trying to build a live wallpaper using frames. The code I’m

  • 0

I’m stuck. I’m trying to build a live wallpaper using frames. The code I’m using is not working. The live wallpaper doesn’t movie through the frames. It only shows the last frame. What should I do to this code to get it to move through its frames? A array method, if so how would I set up a array of images in this code?

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.graphics.Canvas;

import android.service.wallpaper.WallpaperService;

import android.view.SurfaceHolder;

public class WallpaperSer extends WallpaperService {

    public void onCreate() 

    {
        super.onCreate();
    }

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

    public Engine onCreateEngine() 
    {
        return new WallpaperSerEngine();
    }

    class WallpaperSerEngine extends Engine 
    {
        public Bitmap image1, image2, image3, image4, image5, image6, image7, image8, image9,image10,
        image11, image12, image13, image14, image15, image16, image17, image18, image19,image20;

        WallpaperSerEngine() 
        {       
                image1 = BitmapFactory.decodeResource(getResources(), R.drawable.and1);
                image2 = BitmapFactory.decodeResource(getResources(), R.drawable.and2);
                image3 = BitmapFactory.decodeResource(getResources(), R.drawable.and3); 
                image4 = BitmapFactory.decodeResource(getResources(), R.drawable.and4);
                image5 = BitmapFactory.decodeResource(getResources(), R.drawable.and5);
                image6 = BitmapFactory.decodeResource(getResources(), R.drawable.and6);
                image7 = BitmapFactory.decodeResource(getResources(), R.drawable.and7);
                image8 = BitmapFactory.decodeResource(getResources(), R.drawable.and8);
                image9 = BitmapFactory.decodeResource(getResources(), R.drawable.and9);
                image10 = BitmapFactory.decodeResource(getResources(), R.drawable.and10);
                image11 = BitmapFactory.decodeResource(getResources(), R.drawable.and11);
                image12 = BitmapFactory.decodeResource(getResources(), R.drawable.and12);
                image13 = BitmapFactory.decodeResource(getResources(), R.drawable.and13); 
                image14 = BitmapFactory.decodeResource(getResources(), R.drawable.and14);
                image15 = BitmapFactory.decodeResource(getResources(), R.drawable.and15);
                image16 = BitmapFactory.decodeResource(getResources(), R.drawable.and16);
                image17 = BitmapFactory.decodeResource(getResources(), R.drawable.and17);
                image18 = BitmapFactory.decodeResource(getResources(), R.drawable.and18);
                image19 = BitmapFactory.decodeResource(getResources(), R.drawable.and19);
                image20 = BitmapFactory.decodeResource(getResources(), R.drawable.and20);
        }

        public void onCreate(SurfaceHolder surfaceHolder) 
        {
            super.onCreate(surfaceHolder);
        }

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

        }

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

            Canvas c = null;
            try 
            {
                c = holder.lockCanvas();
                if (c != null) 
                {              
                     c.drawBitmap(image1, 0, 0, null);
                     c.drawBitmap(image2, 0, 0, null);
                     c.drawBitmap(image3, 0, 0, null);
                     c.drawBitmap(image4, 0, 0, null);
                     c.drawBitmap(image5, 0, 0, null);
                     c.drawBitmap(image6, 0, 0, null);
                     c.drawBitmap(image7, 0, 0, null);
                     c.drawBitmap(image8, 0, 0, null);
                     c.drawBitmap(image9, 0, 0, null);
                     c.drawBitmap(image10, 0, 0, null);
                     c.drawBitmap(image11, 0, 0, null);
                     c.drawBitmap(image12, 0, 0, null);
                     c.drawBitmap(image13, 0, 0, null);
                     c.drawBitmap(image14, 0, 0, null);
                     c.drawBitmap(image15, 0, 0, null);
                     c.drawBitmap(image16, 0, 0, null);
                     c.drawBitmap(image17, 0, 0, null);
                     c.drawBitmap(image18, 0, 0, null);
                     c.drawBitmap(image19, 0, 0, null);
                     c.drawBitmap(image20, 0, 0, null);
                }
            } finally 
            {
                if (c != null) holder.unlockCanvasAndPost(c);
            }
        }
    }
}

This Is a edit To my code. Not the solution….

 import android.graphics.Bitmap;

 import android.graphics.BitmapFactory;

 import android.graphics.Canvas;

 import android.os.Handler;

 import android.service.wallpaper.WallpaperService;

 import android.view.SurfaceHolder;

 public class WallpaperSer extends WallpaperService {

int incrementer=0;
Bitmap bmps[]=new Bitmap[10];

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

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

public Engine onCreateEngine() 
{
    return new WallpaperSerEngine();
}

class WallpaperSerEngine extends Engine 
{

    int res[]={R.drawable.and1,R.drawable.and2,R.drawable.and3,R.drawable.and4,R.drawable.and5,R.drawable.and6,R.drawable.and7,R.drawable.and8,R.drawable.and9,R.drawable.and10};
    WallpaperSerEngine() 
    {  
          for(int i=0;i<=10;i++)
              {
                    bmps[i]= BitmapFactory.decodeResource(getResources(),res[i]);                     
               }
    }
}

    private final Handler handler = new Handler();
     private final Runnable drawRunner = new Runnable() {
            @Override
            public void run() {

                  drawFrame();
                  handler.removeCallbacks(drawRunner);

                  handler.postDelayed(drawRunner, 200);
            }

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

            Canvas c = null;
            try 
            {
                c = holder.lockCanvas();
                if (c != null) 
                {              

                     c.drawBitmap(bmps[incrementer], 0, 0, null);

                    incrementer=(incrementer==10)?0 : incrementer+1; 
                }
            } finally 
            {
                if (c != null) holder.unlockCanvasAndPost(c);
            }
        }

        private SurfaceHolder getSurfaceHolder() {
            // TODO Auto-generated method stub
            return null;
        }
    }
  • 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-06-04T13:12:10+00:00Added an answer on June 4, 2026 at 1:12 pm

    You have to register a Handler and make use of some threads.

    But first of all add a global int like this,

    int incrementer=0;

    See this modified code of yours.

    1) Inside your WallpaperSerEngine class, create a Handler like this,

     private final Handler handler = new Handler(); 
    

    2) Similarly add a Runnable inside WallpaperSerEngine class and call your drawFrame(),

     private final Runnable drawRunner = new Runnable() {
            @Override
            public void run() {
    
                  drawFrame();              
            }
    
        };
    

    3) Add the below lines to the bottom of your drawFrame() to ensure that your runnable is called on a certain time interval to draw the frames,

                    handler.removeCallbacks(drawRunner);
    
            handler.postDelayed(drawRunner, 200); //delay milliseconds 200. Change it for your need.
    

    4) Now change your drawFrame() method. YOu cannot do it in this way. You have to make use of some Bitmap Arrays. This is critical. Kindle follow the below steps clearly.

    5) Instead of declaring variable for each bitmap, put it in a Bitmap array .

    Bitmap bmps[]=new Bitmap[10]; // assign its size based on your need. I just need 10 for demo.
    

    6) Now declare a int array for your Drawable resources.

       int res[]={R.drawable.and1,R.drawable.and2,R.drawable.and3,R.drawable.and4,R.drawable.and5,R.drawable.and6,R.drawable.and7,R.drawable.and8,R.drawable.and9,R.drawable.and10};
    

    7) Now change your WallpaperSerEngine() like this.

    WallpaperSerEngine() 
            {  
                  for(int i=0;i<=10;i++)
                      {
                            bmps[i]= BitmapFactory.decodeResource(getResources(),res[i]);                     
                       }
            }
    

    8) And now finally a little bit modification in your drawFrame(),

    void drawFrame() 
            {
                final SurfaceHolder holder = getSurfaceHolder();
    
                Canvas c = null;
                try 
                {
                    c = holder.lockCanvas();
                    if (c != null) 
                    {              
    
                         c.drawBitmap(bmps[incrementer], 0, 0, null);
    
                        incrementer=(incrementer==10)?0 : incrementer+1; 
                    }
                } finally 
                {
                    if (c != null) holder.unlockCanvasAndPost(c);
                }
            }
        }
    

    That’s it. You should be seeing your frames now. And accept it if this is helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported

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.