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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:04:49+00:00 2026-05-24T08:04:49+00:00

I have problem with something, which should work as a timer. I have read

  • 0

I have problem with something, which should work as a timer. I have read this article according to the using “timer” in Android:
http://developer.android.com/resources/articles/timed-ui-updates.html

I have the TextView and ImageView in my layout. I have AnimationDrawable in this ImageView. I have overrided the AnimationDrawable class, because I want to know when my animation is completed. However, the runnable I want to call when my animation is ended – work properly. But in case, when I want to upadate TextView each second, another runnable (in the code below) is calling only once (I can see the number “1” during all the animation).

TextView timeFlow;
int seconds;

private Runnable mUpdateTimeTask = new Runnable() {
       public void run() {            
           seconds++;             
           timeFlow.setText(String.valueOf(seconds));          
       }
};

private void startAnimation() {      
    image = (ImageView) this.findViewById(R.id.image);      
    recordImage.setBackgroundResource(R.drawable.record_animation);
    timeFlow = (TextView) this.findViewById(R.id.time_flow);
    timeFlow.setText("...");            

    image.post(new Runnable() { 
    @Override
    public void run() {
        CustomAnimationDrawable currentAnimation = new CustomAnimationDrawable((AnimationDrawable) recordImage.getBackground());
        currentAnimation.setOnFinishCallback(runnable);
        recordImage.setBackgroundDrawable(currentAnimation);
        currentAnimation.start();                               

        handler.removeCallbacks(mUpdateTimeTask);
        handler.postDelayed(mUpdateTimeTask, 100);                                          
        }
    });     
}
  • 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-24T08:04:50+00:00Added an answer on May 24, 2026 at 8:04 am

    You cannot call a UI method from a worker thread. Instead you need to change the code in mUpdateTimeTask to

    private Runnable mUpdateTimeTask = new Runnable() {
        public void run() {            
             seconds++;             
             timeFlow.post(new Runnable() {
                   timeFlow.setText(String.valueOf(seconds));
             });
             // It's not clear if handler is accessible here, but you get the picture.
             handler.postDelayed(mUpdateTimeTask, 100); 
        }
    };
    

    The Worker Thread section in the android dev guide has more examples.

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

Sidebar

Related Questions

I have a problem drawing something quickly in .NET. I don't think that any
I am somewhat new to jQuery and I have a problem with something I
Problem -- I have something like the following entries, 1000 of them: args1=msg args2=flow
I need to use something like get_or_create() but the problem is that I have
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
Problem: I have to design an algorithm, which does the following for me: Say
I am aware that System.Threading.Timer exists, but I already have a Thread. This thread
Here's something I think should work (and I believe I once had it working)
I guess this is a quite simple (read: very simple) question, but I have
I have a #search element, which when the keyup event occurs should fire a

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.