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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:34:54+00:00 2026-06-12T20:34:54+00:00

I use functions for canvas like drawCircle and drawPoint in android. This works fine.

  • 0

I use functions for canvas like drawCircle and drawPoint in android.
This works fine.

But the problem now is to draw these different items with a delay, so it looks like an animation.

What kind of mechanism should I use? Have tried with async but I dont like that way of doing it.

Should I use some kind of timer that just draw with an interval or is there other clever ways to do this?

  • 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-12T20:34:55+00:00Added an answer on June 12, 2026 at 8:34 pm

    I use this strategy, first I declare a Handler and a Runnable that way:

        private final Observable mObservable = new Observable();
        private final static int TIME_STEP_MS = 5;
        private final Handler mHandler = new Handler();
        private final Runnable mTimeManager = new Runnable() 
        {
            public void run() 
            {
                mObservable.notifyObservers(TIME_STEP_MS);
                mHandler.postDelayed(mTimeManager, TIME_STEP_MS);
            }
        };
    

    Then when I want to start my time manager I just call the mTimeManager.run() and it will start to notify my Observer s (previously added) periodically.

    If you need for some reason stop the timer or something you just do that:

        mHandler.removeCallbacks(mTimeManager);
    

    [ EDIT – More complete code ]

    Ok than let’s make it clearer, first I made a custom Observable object like that [that’s optional]:

        private final Observable mObservable = new Observable()
        {
            public void notifyObservers()
            {
                setChanged();
                super.notifyObservers();
            };
    
            @Override
            public void notifyObservers(Object data) 
            {
                setChanged();
                super.notifyObservers(data);
            };
        };
    

    the reason for that is just because I can’t call setChanged() outside Observable class – it’s protected, if it’s not changed it doesn’t notify any observer.

    The other declarations keep the same as shown before, now I need to start this TimeManager somewhere, my app is a LiveWallpaper and I make all rendering stuff into a class that extends a Thread but you don’t need that necessarily, I made a method called resumeDrawing(), this one is called right after super.start(); at my @Override of public synchronized void start() from Thread class, the method looks like that:

        public void resumeDrawing()
        {
            if (!mTimeManagerRunning) // just a boolean field in my class
            {
                System.err.println("Resuming renderer."); // just for debug
                mTimeManager.run();
                mTimeManagerRunning = true;
            }
            else
            {
                System.err.println("Renderer already running."); // just for debug
            }
        }
    

    and it’s dual:

        public void pauseDrawing()
        {
            if (mTimeManagerRunning)
            {
                System.err.println("Pausing renderer.");
                mHandler.removeCallbacks(mTimeManager);
                mTimeManagerRunning = false;
            }
            else
            {
                System.err.println("Renderer already paused.");
            }
        }
    

    Ok, now we can start and stop the time manager, but who’s listening? Nobody! so let’s add’em: On the constructor of my Renderer I add some Observer s to my mObservable object, one of those is the Renderer itself, so my renderer extends Thread and implements Observer:

        @Override // from Observer interface
        public void update(Observable arg0, Object arg1) 
        {
            mElapsedMsRedraw += (Integer) arg1; 
    
            if (mElapsedMsRedraw >= mDrawingMsPerFrame)
            {
                mElapsedMsRedraw = 0;
                drawEm(); // refresh the canvas and stuff
            }
        }
    

    to add observers you simply do mObservable.addObserver(THE_OBJECT - Implements Observer)

    you can see that I don’t re-render my stuff each time I’m notified, that’s because I use this TimeManager for other thinks than just refresh the Canvas like updating the position of the objects I want to draw just internally.

    So, what you need to slow down the drawing is to change the way your objects change internally while the time passes, I mean your circles and points etc, or you can chance your time step, I recommend the first one.

    Was it clearer? I hope it helps.

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

Sidebar

Related Questions

I often use convenience functions that return pointers to static buffers like this: char*
I'd like to use HTML5 Canvas, but I'd like to use it in terms
I use functions like the following to make temporary tables out of crosstabs queries.
I was wondering if there was anyway to use functions like ReadFileEx that require
I use this functions for load configuration for particular extension function! LoadSnippets(extension) let file
I use Log functions to debug my Android app. I'm close to releasing my
I'm using canvas to draw a chart. I would like make it animated, which
i have few variables like this: self.lamp_1 self.lamp_2 self.lamp_3 self.lamp_4 and now i want
As we know many HTML 5 renderers use the GPU to draw canvas elements.
I'd like to use jQuery with Google maps. I'm trying to replicate this 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.