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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:05:16+00:00 2026-06-01T20:05:16+00:00

I have a code sample that uses this function to run a thread runOnUiThread

  • 0

I have a code sample that uses this function to run a thread runOnUiThread. why and when may we need to use it?

edit

What about to use AsyncTask class, what’s the pros and cons??

  • 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-01T20:05:17+00:00Added an answer on June 1, 2026 at 8:05 pm

    You have to use runOnUiThread() when you want to update your UI from a Non-UI Thread. For eg- If you want to update your UI from a background Thread. You can also use Handler for the same thing.

    From the Docs –

    Runs the specified action on the UI thread. If the current thread is
    the UI thread, then the action is executed immediately. If the current
    thread is not the UI thread, the action is posted to the event queue
    of the UI thread.

    Syntax –

           Activity_Name.this.runOnUiThread(new Runnable() {
    
                @Override
                public void run() {
                    // your stuff to update the UI
    
                }
            });
    

    Update –

    AsyncTask -
    

    If you want to do some Network operation or anything that blocks
    your UI in that case AsyncTask is best options. There are several
    other ways for performing the same Background Operations as you can
    use Service, IntentService also for doing Background Operations.
    Using AsyncTask will help you doing your UI work and also won’t block
    your UI until your background Operation is going on.

    From the Docs –

    AsyncTask enables proper and easy use of the UI thread. This class
    allows to perform background operations and publish results on the UI
    thread without having to manipulate threads and/or handlers.

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

Sidebar

Related Questions

I have seen sample source code around that uses different ways of releasing/dealloc'ing objects,
Does anybody have a short code sample that can be run in the VS
I have this simple code that speaks for itself. <script language='javascript"> function check() {}
I need a concrete sample of code with doctrine 2 that uses polymorphic associations.
I'm using Grails 1.3.7. I have some code that uses the built-in base64Encode function
I have a code sample that gets a SEL from the current object, SEL
I have the following code sample that im trying to wrap my head around
I have been scouring the web for a code sample that shows how to
I have to create an sample code that connect to a socket server, and
Trying to get comfortable with jQuery and I have encountered some sample code that

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.