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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:37:27+00:00 2026-05-23T09:37:27+00:00

Asynctask have 4 override methods onPreExecute() , doInBackground() , onProgressUpdate() , onPostExecute() except onProgressUpdate

  • 0

Asynctask have 4 override methods onPreExecute(), doInBackground(), onProgressUpdate(), onPostExecute()
except onProgressUpdate all are working.
What should I do so that onProgressUpdate() should work.
Can anybody please briefly explain me what’s the use of onProgressUpdate(), what should write within this?

  • 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-23T09:37:27+00:00Added an answer on May 23, 2026 at 9:37 am

    onProgressUpdate() is used to operate progress of asynchronous operations via this method. Note the param with datatype Integer. This corresponds to the second parameter in the class definition. This callback can be triggered from within the body of the doInBackground() method by calling publishProgress().

    Example

    import android.app.Activity;
    import android.content.Context;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TextView;
    
    public class AsyncTaskExample extends Activity {
    
        protected TextView _percentField;
    
        protected Button _cancelButton;
    
        protected InitTask _initTask;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            _percentField = (TextView) findViewById(R.id.percent_field);
            _cancelButton = (Button) findViewById(R.id.cancel_button);
            _cancelButton.setOnClickListener(new CancelButtonListener());
            _initTask = new InitTask();
            _initTask.execute(this);
        }
    
        protected class CancelButtonListener implements View.OnClickListener {
    
            public void onClick(View v) {
                _initTask.cancel(true);
            }
        }
    
        /**
         * sub-class of AsyncTask
         */
        protected class InitTask extends AsyncTask<Context, Integer, String> {
    
            // -- run intensive processes here
            // -- notice that the datatype of the first param in the class definition matches the param passed to this
            // method
            // -- and that the datatype of the last param in the class definition matches the return type of this method
            @Override
            protected String doInBackground(Context... params) {
                // -- on every iteration
                // -- runs a while loop that causes the thread to sleep for 50 milliseconds
                // -- publishes the progress - calls the onProgressUpdate handler defined below
                // -- and increments the counter variable i by one
                int i = 0;
                while (i <= 50) {
                    try {
                        Thread.sleep(50);
                        publishProgress(i);
                        i++;
                    }
                    catch (Exception e) {
                        Log.i("makemachine", e.getMessage());
                    }
                }
                return "COMPLETE!";
            }
    
            // -- gets called just before thread begins
            @Override
            protected void onPreExecute() {
                Log.i("makemachine", "onPreExecute()");
                super.onPreExecute();
            }
    
            // -- called from the publish progress
            // -- notice that the datatype of the second param gets passed to this method
            @Override
            protected void onProgressUpdate(Integer... values) {
                super.onProgressUpdate(values);
                Log.i("makemachine", "onProgressUpdate(): " + String.valueOf(values[0]));
                _percentField.setText((values[0] * 2) + "%");
                _percentField.setTextSize(values[0]);
            }
    
            // -- called if the cancel button is pressed
            @Override
            protected void onCancelled() {
                super.onCancelled();
                Log.i("makemachine", "onCancelled()");
                _percentField.setText("Cancelled!");
                _percentField.setTextColor(0xFFFF0000);
            }
    
            // -- called as soon as doInBackground method completes
            // -- notice that the third param gets passed to this method
            @Override
            protected void onPostExecute(String result) {
                super.onPostExecute(result);
                Log.i("makemachine", "onPostExecute(): " + result);
                _percentField.setText(result);
                _percentField.setTextColor(0xFF69adea);
                _cancelButton.setVisibility(View.INVISIBLE);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this AsyncTask that loads a WebView in onPostExecute that otherwise works
I'm beginning to think that to get a ProgressDialog to work the AsyncTask has
I have an AsyncTask that get info from the web. Sometimes the connection fails
i have developed a simple AsyncTask class that takes Handlers as its parameters and
I have an asynctask of which's onPostExecute i am calling a function to show
I have an AsyncTask when onPreExecute function executes it gives me an exception **
I have a method that is executed using asyncTask with a progressdialog. After this
I have an AsyncTask which launches a DatabaseHelper class from DoinBackground which copies an
I have MainActivity which does some Work before it Executes an AsyncTask called Datensammlung.
**Updated: (See below)**I have been looking around for couple of days and can't find

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.