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

The Archive Base Latest Questions

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

I was using AsyncTask and just switched over to using a traditional Thread for

  • 0

I was using AsyncTask and just switched over to using a traditional Thread for reasons not worth going into for the sake of this question.

What can I do to make something execute before and after the thread starts, similar to the functionality of onPre/PostExecute?

For example, let’s say I want to display a loading circle before the thread starts, and dismiss it when it finishes. How would I do that?

For the post-execution bit, I’m using thread.join() and it seems to do the trick. I’m not sure if that’s the way to go about it though, or how to do something pre-execution.

  • 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-12T22:34:26+00:00Added an answer on June 12, 2026 at 10:34 pm

    What can I do to make something execute before and after the thread starts, similar to the functionality of onPre/PostExecute?

    onPreExecute() -> statements you execute before calling start() on your Thread

    onPostExecute() -> call runOnUiThread(), or post() on a View, from your Thread, supplying a Runnable to be executed on the main application thread

    How would I do that?

    Ideally, you wouldn’t. Progress dialogs suck. Put a progress indicator in your UI somewhere (e.g., action bar, title bar), and disable the few things the user cannot safely do while your thread is in operation.

    That being said, you’d presumably display the DialogFragment before executing the thread, then remove the fragment once the thread is completed via the above mechanisms.

    For the post-execution bit, I’m using thread.join() and it seems to do the trick.

    Ick. That will block whatever thread you are on, and if that’s the main application thread, that’s really bad.


    UPDATE

    Example of runOnUiThread():

    new Thread() {
      public void run() {
        // do cool stuff
        runOnUiThread(new Runnable() {
          public void run() {
            // do other cool stuff quickly on the main application thread
          }
        );
      }
    }).start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I press login button to login into my app and I'm using asyncTask for
I have this strange problem about loading images using AsyncTask in ListView.In my ListView,
I'm using using AsyncTask to download data over internet and I have a little
I'm using AsyncTask to display a progressBar while loading Rss News. Because this is
I have a method that is executed using asyncTask with a progressdialog. After this
I have been using Asynctask most of time, but in the current app the
I am using AsyncTask in my App. How can i make my Task resume
I am using AsyncTask and want to use getApplication() to work with class Application.
I am using AsyncTask to set my items and stuff, in the postExecute i
i am using asynctask to fetch images from given url.these images are displaying in

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.