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

  • Home
  • SEARCH
  • 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 7683821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:53:03+00:00 2026-05-31T18:53:03+00:00

Is it possible start a new thread within an Async task? Something like this:

  • 0

Is it possible start a new thread within an Async task?
Something like this:

public class FirstActivity extends Activity {

protected ProgressBar progBar;
protected Intent intent;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    progBar = (ProgressBar)findViewById(R.id.start_progressBar);
    progBar.setProgress(0);
    new StartingApp().execute();
}

protected class StartingApp extends AsyncTask<Void, Integer, Void> {

    int myProgress;

    @Override
    protected void onPreExecute() {
        myProgress = 0;
    }

    @Override
    protected Void doInBackground(Void... params) {

        while(myProgress<50){
            myProgress++;
            publishProgress(myProgress);
                SystemClock.sleep(10);
            }

        MyRunnableClass mrc = new MyRunnableClass();
        mrc.run();

        return null;    
    }

    @Override
    protected void onPostExecute(Void result){

        intent = new Intent(FirstActivity.this, SecondActivity.class);
        startActivity(intent);
    }

    @Override
    protected void onProgressUpdate(Integer... values) {

        progBar.setProgress(values[0]);
    }
}
}

MyRunnableClass is a class which implements Runnable.
I want something like this because in the first activity I want to show a progress bar while the application is initializing (fill data structures, starting threads).

Another question I have is: should I use the run() or start() method?

Thanks in advance!

  • 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-31T18:53:05+00:00Added an answer on May 31, 2026 at 6:53 pm

    Why do you want to do that?
    As pointed out in the code you need to call new Thread(mrc).start() to make it work. Otherwise i dont see any problem in that code spawning a new thread.

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

Sidebar

Related Questions

Possible Duplicate: Returning a value from thread? I have this code: //Asynchronously start the
Given the code: new Thread(new BackgroundWorker()).start(); Intuitively it feels like the BackgroundWorker instance should
This is the traditional thread creation code: public static void Ping() { new Thread(workThreadPingRequest)
So the following code is possible in C# to start a new thread in
Is it possible to get a thread dump of a Java Web Start application?
I know this is possible but I'm not really sure where to start. Has
When I'm inside a destructor is it possible that some other thread will start
Quick question: Is it possible to showDialog/Show form from a new thread that has
Is it possible to call a non-static function that uses a public non-static class
Code: final ProgressDialog pd = ProgressDialog.show(Main.this,,Loading. Please wait..., true); pd.show(); Thread t = new

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.