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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:20:25+00:00 2026-06-02T08:20:25+00:00

I am working on Android AsyncTask, I wish to make a progress bar during

  • 0

I am working on Android AsyncTask, I wish to make a progress bar during my program is loading. Here’s how I make it.

A class is declared here...
private ArrayList<String> result1 = new ArrayList<String>(); //class variable

onCreate()
{
    Some stuff here...
    new ATask().execute();
     for (int i = 0; i <result1.size();i++)
    {
        output = output +result1.get(i) + "\n\n";
    }
    textView.setText(output);
}
private void do0()
{
    ArrayList<Sentence> result = new ArrayList<Sentence>();
    ArrayList<String> result2 = new ArrayList<String>();
    result = do1("link", true); //just some function I am working
    result1 = do2(result,10);//do2 return ArrayList<String>
}
private class ATask extends AsyncTask<String, Void, String>{
    private ProgressDialog progress = null;
    @Override
    protected String doInBackground(String... params) {
        do0();
        return null;
    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
    }

    @Override
    protected void onPostExecute(String result) {
        progress.dismiss();

        //adapter.notifyDataSetChanged();

        super.onPostExecute(result);
    }

    @Override
    protected void onPreExecute() {
        progress = new ProgressDialog(ReadWebPage.this);

        progress.setMessage("Doing...");
        progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progress.show();

        super.onPreExecute();
    }

    @Override
    protected void onProgressUpdate(Void... values) {
        super.onProgressUpdate(values);
    }
};

My intention is that, while the progress bar is loading, it will finish the do0() and modify result1, then my oncreate can use that result1 to display in it’s TextView. However my TextView is always empty in this setting. So I move the

     for (int i = 0; i <result1.size();i++)
    {
        output = output +result1.get(i) + "\n\n";
    }
    textView.setText(output);

into the do0() (right after the result1 = do2()), but then the program will crash. I am not familiar with these thread settings, thanks for your help 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-06-02T08:20:27+00:00Added an answer on June 2, 2026 at 8:20 am

    You’ll be better served with a thread that holds a Handler object that was initialized on the main thread. Using the handler, you can post() little snippets to be executed on a main thread – like update a progress bar. You can do the same Handler trick from the AsyncTask, but IMHO threads are cleaner.

    Said snippets should be implemented as Runnables. Feel free to use a nested anonymous class one-liner.

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

Sidebar

Related Questions

As you might know, Android's SDK features a AsyncTask class which allows for code
Can anybody tell about the asynctask used in android application. Currently I am working
I'm working with Android and I really need a fast way to get a
I am working in android. I designed a video player in my application. Most
I am working on android apps. I want to add a contact in android
I am working on android chat application. I am facing a problem in send
I am working in android. I just used a video player. I am accessing
I just started working with Android and I have a problem with my map.
I am working in android. I am using VideoView. Its stretched vertically when orientation
I am working in android. I want to create a chat room dynamically using

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.