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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:24:01+00:00 2026-05-21T17:24:01+00:00

I’m running an activity, which has to download a fairly large image from the

  • 0

I’m running an activity, which has to download a fairly large image from the Internet, and then display it. This works: the download is done via an AsyncTask, and a progress dialog is shown. And when the download is finished, the activity showing the image is called.

The problem I have is that the real work is done in an external class. This as other activities call the same routine to fetch an image. So I can not immediately call postUpdate() to set the update as this call would be done in another class. Now I wonder how I can get the progress updates back to my AsyncTask so my progress dialog can show the actual progress made

The AsyncTask subclass currently looks like this:

private class StartShowImage extends AsyncTask<String, Integer, String> {

    private ProgressDialog dialog;

    @Override
    protected void onPreExecute() {

        // Toon een dialog met draaiend wiel terwijl we de foto
        // aan het ophalen zijn.
        dialog = new ProgressDialog(ShowDeaddrop.this);
        dialog.setTitle(R.string.progress_dialog_title);
        dialog.setMessage(getResources().getString(
                R.string.progress_dialog_fetching_image));
        dialog.show();
    }

    /**
     * De hoofdroutine; haalt de foto op.
     */
    @Override
    protected String doInBackground(final String... params) {
        final String imageName = params[0];
        String result = null;
        try {
            result = DeaddropUtil.getImage(context, imageName, ""
                    + deaddropID, true);
        } catch (final IOException e) {
            Log.v(TAG, "Failed to download image " + imageName);
            Log.v(TAG, "" + e);
        }
        return result;
    }

    /**
     * Als we de foto hebben, start ShowImage.
     */
    @Override
    protected void onPostExecute(final String imageName) {
        dialog.dismiss();
        if (isActive)
            if (imageName == null)
                Toast.makeText(context, R.string.toast_show_image_failed,
                        Toast.LENGTH_SHORT).show();
            else {
                final Intent i = new Intent(ShowDeaddrop.this,
                        ShowImage.class);
                i.putExtra("imageName", imageName);
                startActivityForResult(i, SHOW_IMAGE);
            }
    }
     }

isActive is a boolean that keeps track of whether this activity is active – it’s set in onCreate and onResume and unset in onPause.

I’ve been looking into a broadcast intent – I’ve seen an example on how to send back such an intent to the main activity, but the problem is that the listener has to be registered/unregstered in onResume/onPause – and AsyncTask is a separate thread. So it seems this method can not be used safely that way.

Edit restating the question, hoping to get answers that address my question.

AsyncTask sets up progress dialog.

The onExecute() thread can directly update the progress dialog. No problem there.

The actual work is done in an external class, so the progress information is known by that external class, which has to communicate it back to the AsyncTask one way or another.

AsyncTask will have to have some kind of listener, or handler, or something that the external class can call back to, in order to give progress updates.

The question is: how to perform this last part of the process? What is a suitable listener? How to implement such a listener? Which thread does the listener end up in – the UI thread like .onPreExecute() and .onPostExecute(), or the work thread from .doInBackground()?

  • 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-21T17:24:02+00:00Added an answer on May 21, 2026 at 5:24 pm

    Solved by using a BroadcastIntent.

    Main activity creates BroadcastReceiver, IntentFilter and progress dialog; AsyncTask registers/unregisters this receiver and shows/dismisses the dialog in onPreExecute/onPostExecute respectively.

    With extra bits in onResume and onPause to not have active receivers when the activity itself is inactive.

    It took me a while to understand this intent broadcast, but after that it was a very quick and easy implementation.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I am currently running into a problem where an element is coming back from
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.