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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:28:52+00:00 2026-06-11T16:28:52+00:00

When using a AsyncTaskLoader how would you update a progressbar showing the status as

  • 0

When using a AsyncTaskLoader how would you update a progressbar showing the status as it is being updated? Normally you wait for the callback to remove when done, but how to do running updates?
Would you let the main thread (ui) poll the data as it is being set or something?

Edit: I’m talking about AsyncTaskLoader, look at the loader part. Here is link to class: http://developer.android.com/reference/android/content/AsyncTaskLoader.html

I want to use it because its the future :), I know how to do this with AsyncTask.

  • 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-11T16:28:53+00:00Added an answer on June 11, 2026 at 4:28 pm

    You can do that with loaders, but you need to keep and update a WeakReference on your Activity :

    public class LoaderTestActivity extends FragmentActivity implements LoaderCallbacks<Void> {
        private static final int MAX_COUNT = 100;
    
        private ProgressBar progressBar;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_async_task_test);
    
            progressBar = (ProgressBar) findViewById(R.id.progressBar1);
            progressBar.setMax(MAX_COUNT);
            AsyncTaskCounter.mActivity = new WeakReference<LoaderTestActivity>(this);
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_async_task_test, menu);
            return true;
        }
    
        public void onStartButtonClick(View v) {
            startWork();
        }
    
        void startWork() {
            getSupportLoaderManager().initLoader(0, (Bundle) null, this);
        }
    
        static class AsyncTaskCounter extends AsyncTaskLoader<Void> {
            static WeakReference<LoaderTestActivity> mActivity;
    
            AsyncTaskCounter(LoaderTestActivity activity) {
                super(activity);
                mActivity = new WeakReference<LoaderTestActivity>(activity);
            }
    
            private static final int SLEEP_TIME = 200;
    
            @Override
            public Void loadInBackground() {
                for (int i = 0; i < MAX_COUNT; i++) {
                    try {
                        Thread.sleep(SLEEP_TIME);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    Log.d(getClass().getSimpleName(), "Progress value is " + i);
                    Log.d(getClass().getSimpleName(), "getActivity is " + getContext());
                    Log.d(getClass().getSimpleName(), "this is " + this);
    
                    final int progress = i;
                    if (mActivity.get() != null) {
                        mActivity.get().runOnUiThread(new Runnable() {
    
                            @Override
                            public void run() {
                                mActivity.get().progressBar.setProgress(progress);
                            }
                        });
                    }
                }
                return null;
            }
    
        }
    
        @Override
        public Loader<Void> onCreateLoader(int id, Bundle args) {
            AsyncTaskLoader<Void> asyncTaskLoader = new AsyncTaskCounter(this);
            asyncTaskLoader.forceLoad();
            return asyncTaskLoader;
        }
    
        @Override
        public void onLoadFinished(Loader<Void> arg0, Void arg1) {
    
        }
    
        @Override
        public void onLoaderReset(Loader<Void> arg0) {
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement an AsyncTaskLoader in my project using the Compatibility Package, so
Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange
Using Rails 3.2.0 with haml and sass: I Would like to link an external
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using Jenkins or Hudson I would like to create a pipeline of builds with
Using this example . Pretend there are date fields in both forms. How would
Using Xcode4.2.1, with a basic PhoneGap template based app. (I say template, but I
When using a custom AsyncTaskLoader to download data from a web service, if I
Using android-support-v4.jar and FragmentActivity (no fragments at this point) I have an AsyncTaskLoader which
Using Rails 3, but I guess doesn't matter. I put this in the template

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.