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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:59:42+00:00 2026-05-27T20:59:42+00:00

I need to update UI after certain time period, for which I have create

  • 0

I need to update UI after certain time period, for which I have create a timer schedule and inside it I am calling the runOnUiThread.

timer.scheduleAtFixedRate(new TimerTask() {

            public void run() {
                System.out.println("1");
                    try {

                    System.out.println("2");
                    System.out.println("3");

                    runOnUiThread(new  Runnable() {

                        public void run() {
                            System.out.println("4");
                            System.out.println("5");
                            System.out.println("6");
                            System.out.println("7");
                        }
                    });

                    System.out.println("8");
                } catch (Exception e) {

                    e.printStackTrace();
                }

            }

        }, delay, period);
        System.out.println("9");

I am having the problem that after reaching “3”, timer thread jumps to “8” and after that the UI thread runs from “4”.
I want to make timer thread to wait till UI thread completes its work at “7” only then it should move to “8”.

Sample Output

01-05 00:30:16.308: I/System.out(1394): 1
01-05 00:30:16.308: I/System.out(1394): 2
01-05 00:30:16.308: I/System.out(1394): 3
01-05 00:30:16.308: I/System.out(1394): 8
01-05 00:30:16.308: I/System.out(1394): 4
01-05 00:30:16.308: I/System.out(1394): 5
01-05 00:30:16.308: I/System.out(1394): 6
01-05 00:30:16.308: I/System.out(1394): 7
01-05 00:30:17.307: I/System.out(1394): 1
01-05 00:30:17.307: I/System.out(1394): 2
01-05 00:30:17.307: I/System.out(1394): 3
01-05 00:30:17.307: I/System.out(1394): 8
01-05 00:30:17.307: I/System.out(1394): 4
01-05 00:30:17.323: I/System.out(1394): 5
01-05 00:30:17.323: I/System.out(1394): 6
01-05 00:30:17.323: I/System.out(1394): 7
  • 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-27T20:59:43+00:00Added an answer on May 27, 2026 at 8:59 pm

    Try this

    Object lock=new Object();
    timer.scheduleAtFixedRate(new TimerTask() {
    
            public void run() {
                System.out.println("1");
                    try {
    
                    System.out.println("2");
                    System.out.println("3");
    
                    runOnUiThread(new  Runnable() {
    
                        public void run() {
                            System.out.println("4");
                            System.out.println("5");
                            System.out.println("6");
                            System.out.println("7");
                            synchronized(lock){lock.notify();}
                        }
                    });
                    try{
                       synchronized(lock){lock.wait();}
                    }catch(InterruptedException x){}
                    System.out.println("8");
                } catch (Exception e) {
    
                    e.printStackTrace();
                }
    
            }
    
        }, delay, period);
        System.out.println("9");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found that after a certain amount of time, the Facebook session that
I'm building something which has a countdown to a certain date/time. I have it
I have a mySql query which adds certain interval of time to datetime field.
I need to restart the program that im working on after an update has
I need to update a field (which is currently empty) based on a match
I am trying to update the ListView with timer . I have implemented the
I need to update a certain row in table, already did validators to assure
I need to update my application after the user pays for an update. I
I have an on update trigger in SQL Server 2008. I only need to
I need to update a combobox with a new value so it changes the

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.