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 8933029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:26:27+00:00 2026-06-15T09:26:27+00:00

Hello I was trying to Pause Animation Drawable but could not succeeded. With the

  • 0

Hello I was trying to Pause Animation Drawable but could not succeeded. With the help of stack overflow I atleast got the help of animationDrawable end listener here is the code for it . IS there any possible way where I can pause the animation Drawable and Start it from where it has paused …

public abstract class CustomAnimationDrawable extends AnimationDrawable{

    /** Handles the animation callback. */
    Handler mAnimationHandler;
    Runnable r= new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
               onAnimationFinish();
        }
    };

    public CustomAnimationDrawable(AnimationDrawable aniDrawable) {
        /* Add each frame to our animation drawable */
        for (int i = 0; i < aniDrawable.getNumberOfFrames(); i++) {
            this.addFrame(aniDrawable.getFrame(i), aniDrawable.getDuration(i));
        }
    }

    @Override
    public void start() {
        super.start();
        /*
         * Call super.start() to call the base class start animation method.
         * Then add a handler to call onAnimationFinish() when the total
         * duration for the animation has passed
         */
        mAnimationHandler = new Handler();
        mAnimationHandler.postDelayed(r, getTotalDuration());

    }

    /**
     * Gets the total duration of all frames.
     * 
     * @return The total duration.
     */
    public int getTotalDuration() {

        int iDuration = 0;

        for (int i = 0; i < this.getNumberOfFrames(); i++) {
            iDuration += this.getDuration(i);
        }

        return iDuration;
    }

    /**
     * Called when the animation finishes.
     */
    abstract void onAnimationFinish();

     public void destroy()
    {


         mAnimationHandler.removeCallbacksAndMessages(r);
         mAnimationHandler.removeCallbacksAndMessages(null);


    }

}

Kindly please help is there any way i can pause ?

  • 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-15T09:26:28+00:00Added an answer on June 15, 2026 at 9:26 am

    I’ve been looking around, and it doesn’t seem that there’s a way to directly do it. All of the variables and methods for setting the frame in AnimationDrawable are private. However, you can get the index of the frame the animation is on when you hit pause and then create a new animation by iterating through the original animation from the index of the last frame played (and then start over and add the rest if the animation is cyclical).

    I started out with an XML based animation loop, and then just added another one for pause and resume. Here’s what I ended up doing, and it’s working fine so far, with relevant variables listed first.

    private ImageView sphere;
    private AnimationDrawable sphereAnimation;
    private AnimationDrawable sphereResume;
    private AnimationDrawable activeAnimation;
    private Drawable currentFrame;
    private Drawable checkFrame;
    private int frameIndex;
    
    private void pause()
    {
        looping = false;
        sphereResume = new AnimationDrawable();
        activeAnimation.stop();
        currentFrame = activeAnimation.getCurrent();
    
        frameLoop:
        for(int i = 0; i < sphereAnimation.getNumberOfFrames(); i++)
        {
            checkFrame = activeAnimation.getFrame(i);
    
            if(checkFrame == currentFrame)
            {
                frameIndex = i;
                for(int k = frameIndex; k < activeAnimation.getNumberOfFrames(); k++)
                {
                    Drawable frame = activeAnimation.getFrame(k);
                    sphereResume.addFrame(frame, 50);
                }
                for(int k = 0; k < frameIndex; k++)
                {
                    Drawable frame = activeAnimation.getFrame(k);
                    sphereResume.addFrame(frame, 50);
                }
                activeAnimation = sphereResume;
                sphere.setImageDrawable(activeAnimation);
                sphere.invalidate();
                break frameLoop;
            }
        }
    }
    
    private void play()
    {
        looping = false;
        activeAnimation.setOneShot(true);
        activeAnimation.start();
    }
    
    private void stop()
    {
        looping = false;
        activeAnimation.stop();
        activeAnimation = sphereAnimation;
        sphere.setImageDrawable(activeAnimation);
    }
    
    private void loop()
    {
        looping = true;
        stopSoundEffect();
        activeAnimation.setOneShot(false);
        activeAnimation.start();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello i am trying a sqlite database tutorial to build, but its not working
Hello im trying to echo only the 50 letters, but something in my code
Hello I am trying to create a custom expandable listview, but the documentation on
I'm trying to run a Hello World program but am getting the error ./ex1.c:
Hello good people of Stack Overflow, I am having trouble with an application I
Hello i'm trying to test GStreamer on OpenSuse 11.4, to display a webcam, but
Hello im using page nation which is amazing but now im trying to print
Hello i am trying to parse a page in xhtml with python but i
Hello I am trying to get the value of a url with onclick but
Hello i'm trying to use facebook server-side authenticaion to get the access token but

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.