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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:47:02+00:00 2026-05-26T08:47:02+00:00

Here is my AsyncTask class: private class Task extends AsyncTask<Void, Integer, Void> { @Override

  • 0

Here is my AsyncTask class:

    private class Task extends AsyncTask<Void, Integer, Void> {

        @Override protected void onPreExecute() {
            dia = new ProgressDialog(pictures.this);
            dia.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            dia.setMessage("Please wait while content is loaded...");
            dia.setCancelable(false);
            dia.show();
        }

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


            Thread thread = new Thread(null, uploader, "MagentoBackground");
            thread.start();

            //publishProgress(100);  keep this commented or no?
            return null;
        }

        @Override public void onProgressUpdate(Integer... prog) {
            if (prog == null)
                return;
            dia.setProgress(prog[0]);
        }

        @Override  protected void onPostExecute(Void voids) {
            dia.setMessage("Done");
            dia.cancel();
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        }
    }

There is one major and one minor problem I am concerned with right now. Here are the major and minor problems, consecutively:

  • This app’s intention is to take a picture and upload it to a website. As soon as the user hits the ‘OK’ button to upload, the AsyncTask dialog shows, so this is fine. However, it only shows the dialog box for a split second, already 100% completed, and then force closes. However, it is most certainly not 100% complete! When I look at the website and refresh the page, it doesn’t show the picture. (On WiFi, the picture actually does upload near immediately, and when the website is refreshed right away, it shows the new picture. But on 3G, this process can take minutes – which is why I want the user to see the progress of the photo being uploaded).

  • I’m not sure how to use the onProgressUpdate. I’ve tried several tutorials, to no avail. If anyone can state what I can do for this situation, it will be helpful

Edit:

Runnable code:

private Runnable uploader = new Runnable() {
        @Override
        public void run() {

            /**JER 3**/
            if (teacherInfo != null)
                teacher = " - " + teacherInfo ;
            else teacher = "" ;

            if (schoolInfo != null )
                school = " - " + schoolInfo ;
            else school = "" ;


            /********/

            if(Descriptor.desString.equals("")) Descriptor.desString = "No description provided.";

            int sessionId = rapi.createSession(experimentInput.getText().toString(), 
                    name.getText().toString() + teacher + school + " - " + time, 
                    Descriptor.desString, "n/a", "Lowell, MA", "");


            JSONArray dataJSON = new JSONArray();
            JSONArray subData = new JSONArray();

                try {
                    subData.put(curTime); subData.put(Lat); subData.put(Long); subData.put(Descriptor.desString);
                    dataJSON.put(subData);
                }
                catch (JSONException e) {
                    e.printStackTrace();
                }


            Boolean result = rapi.updateSessionData(sessionId, experimentInput.getText().toString(), dataJSON);

            if (result) {
                rapi.uploadPictureToSession(picture, experimentInput.getText().toString(), 
                        sessionId, name.getText().toString() + teacher + school + " - " + time, 
                        name.getText().toString() + Descriptor.desString);
            }

            //if (m_ProgressDialog != null && m_ProgressDialog.isShowing()) m_ProgressDialog.dismiss();
        }
    };
  • 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-26T08:47:03+00:00Added an answer on May 26, 2026 at 8:47 am

    You are starting a new thread inside an already seperated thread.

    doInBackground() gets executed in a different thread then the UI-methods onPreExecute(), onPostExecute() and onProgressUpdate() of the AsyncTask class. All that your async task does here is start a third thread. This takes almost no time. After that your task is finished, resulting in the dialog closing immediately.

    You can do your uploading inside doInBackground(), you don’t need to start a new thread there. That’s what the AsyncTask class does for you already.

    Regarding progress: onProgressUpdate() gets called every time you execute publishProgress(). So this is correctly implemented, you just have to call publishProgress() multiple times during the upload process to update the progressbar accordingly (e.g. every percent sent).

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

Sidebar

Related Questions

private class ExecuteLocations extends AsyncTask<String, Void, Void>{ private final ProgressDialog dialog = new ProgressDialog(ListProfiles.this);
package de.tablayoutexample; import java.util.List; import android.os.AsyncTask; import android.util.Log; public class CallWebServiceTask extends AsyncTask<String, String,
I'm having a problem with the AsyncTask class. It seems like my task stops
I have a class which extends AsyncTask, which is intended to serve as a
i have developed a simple AsyncTask class that takes Handlers as its parameters and
I created a cache for my images here public void putBitmapInDiskCache(URI imageUri, Bitmap avatar)
I have a backgorund thread that extends AsyncTask and which I use in activity
I am running into an issue with the way my asynctasks are executed. Here's
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form

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.