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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:54:06+00:00 2026-06-05T13:54:06+00:00

In my application some data is there which is wrapped into an object. I

  • 0

In my application some data is there which is wrapped into an object.
I am sending this object to the server. Everything work correctly.
Here I want to show progress bar when the data is loading to the server.
For this I am using this code:

ProgressThread progThread;
ProgressDialog progDialog;

int typeBar;
int delay = 40; 
int maxBarValue = 200;
@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case 1:
        progDialog = new ProgressDialog(this);
        progDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progDialog.setMax(maxBarValue);
        progDialog.setMessage("Data uploading to the Server..");
        progThread = new ProgressThread(handler);
        progThread.start();
        return progDialog;

    default:
        return null;
    }
}


final Handler handler = new Handler() {
    public void handleMessage(Message msg) {
        // Get the current value of the variable total from the message data
        // and update the progress bar.
        int total = msg.getData().getInt("total");
        progDialog.setProgress(total);
        if (total <= 0) {
            dismissDialog(typeBar);
            progThread.setState(ProgressThread.DONE);
        }
    }
};

private class ProgressThread extends Thread {

    final static int DONE = 0;
    final static int RUNNING = 1;

    Handler mHandler;
    int mState;
    int total;

    ProgressThread(Handler h) {
        mHandler = h;
    }


    @Override
    public void run() {
        mState = RUNNING;
        total = maxBarValue;
        while (mState == RUNNING) {

            connectServerClass.saveOnServer(Object);

            Message msg = mHandler.obtainMessage();
            Bundle b = new Bundle();
            b.putInt("total", total);
            msg.setData(b);
            mHandler.sendMessage(msg);

            total--; // Count down
        }
    }
    public void setState(int state) {
        mState = state;
    }
}

When user click on button then:

typeBar = 1;
showDialog(typeBar);

connectServerClass.saveOnServer(Object)
by the above line I am sending object to the server. Actually I am sending data to the other class which is connectServerClass and this class send object to the server.
but this code not work correctly. This code connect to the server lots of time.

I use the following Code :

private class Uploader extends AsyncTask<Void, String, Integer>
    {
        private List<File> files;
        private boolean canceled;
        private int uploaded;
        private Account account;
        private ProgressDialog uploadSeekBar;

        public Uploader(Account a, List<File> files)
        {
            this.account = a;
            this.files = files;
        }

        @Override
        protected void onPreExecute()
        {
            uploadSeekBar.setMax(files.size());
            uploadSeekBar.setProgress(0);
            uploadSeekBar.setVisibility(View.VISIBLE);  //Error: the method setVisibility is undefined
        }

        @Override
        protected void onPostExecute(Integer result)
        {
            uploadSeekBar.setVisibility(View.INVISIBLE);
            Toast.makeText(Upload.this, result + " files uploaded", // Error: Upload cannot be resolved to a type
                    Toast.LENGTH_LONG).show();
        }

        @Override
        protected void onCancelled()
        {
            // XXX need a way to actually cancel the last upload
            Toast.makeText(Upload.this, "canceling upload", Toast.LENGTH_LONG)
                    .show();
            this.canceled = true;
            uploadSeekBar.setVisibility(View.INVISIBLE);

        }

        @Override
        protected Integer doInBackground(Void... voids)
        {
            uploaded = 0;
            try
            {
                Iterator<File> it = this.files.iterator();
                while (!canceled && it.hasNext())
                {
                    File file = it.next();
                    it.remove();

                    String msg = "";

                    try
                    {
                        if (debugMode)  // what is this debugMode
                        {
                                                //Put your uploading code here.
                            msg = ("fake uploading " + file);
                            Thread.sleep(3000);
                        } else
                        {
                            msg = ("uploading: " + file);
                            controller.uploadFile(file, this.account); //Error: controller cannot be resolved
                        }

                        uploaded++;
                        publishProgress(msg);

                    } catch (IOException e)
                    {
                        controller.te("error uploading file: " + file);
                        controller.te("error uploading file: " + e);
                    } catch (InterruptedException e)
                    {
                    }
                }
            } catch (Exception e)
            {
                publishProgress("error uploading: " + e);
            }

            return uploaded;
        }

        @Override
        protected void onProgressUpdate(String... strings)
        {
            uploadSeekBar.setProgress(uploaded);
            updateUploadMessage(files.size());
            Toast.makeText(Upload.this, strings[0], Toast.LENGTH_LONG).show(); //Error: The method updateUploadMessage(int) is undefined for the type FirstActivity.Uploader 
        }
    }

But I facing some error which I mention as comment in the right side of that line. Please suggest me.

  • 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-05T13:54:08+00:00Added an answer on June 5, 2026 at 1:54 pm

    I will strongly recommend you to Use AsyncTask.

    Below Code snippet will help you on How your AsyncTask should look like.

    package org.sample;
    
    import java.io.File;
    import java.io.IOException;
    import java.util.Iterator;
    import java.util.List;
    
    import android.accounts.Account;
    import android.os.AsyncTask;
    import android.view.View;
    import android.widget.Toast;
    
        private class Uploader extends AsyncTask<Void, String, Integer>
        {
            private List<File> files;
            private boolean canceled;
            private int uploaded;
    
            public Uploader(Account a, List<File> files)
            {
                this.account = a;
                this.files = files;
            }
    
            @Override
            protected void onPreExecute()
            {
                uploadSeekBar.setMax(files.size());
                uploadSeekBar.setProgress(0);
                uploadSeekBar.setVisibility(View.VISIBLE);
            }
    
            @Override
            protected void onPostExecute(Integer result)
            {
                uploadSeekBar.setVisibility(View.INVISIBLE);
                Toast.makeText(Upload.this, result + " files uploaded",
                        Toast.LENGTH_LONG).show();
            }
    
            @Override
            protected void onCancelled()
            {
                // XXX need a way to actually cancel the last upload
                Toast.makeText(Upload.this, "canceling upload", Toast.LENGTH_LONG)
                        .show();
                this.canceled = true;
                uploadSeekBar.setVisibility(View.INVISIBLE);
    
            }
    
            @Override
            protected Integer doInBackground(Void... voids)
            {
                uploaded = 0;
                try
                {
                    Iterator<File> it = this.files.iterator();
                    while (!canceled && it.hasNext())
                    {
                        File file = it.next();
                        it.remove();
    
                        String msg = "";
    
                        try
                        {
                            if (debugMode)
                            {
                                                    //Put your uploading code here.
                                msg = ("fake uploading " + file);
                                Thread.sleep(3000);
                            } else
                            {
                                msg = ("uploading: " + file);
                                controller.uploadFile(file, this.account);
                            }
    
                            uploaded++;
                            publishProgress(msg);
    
                        } catch (IOException e)
                        {
                            controller.te("error uploading file: " + file);
                            controller.te("error uploading file: " + e);
                        } catch (InterruptedException e)
                        {
                        }
                    }
                } catch (Exception e)
                {
                    publishProgress("error uploading: " + e);
                }
    
                return uploaded;
            }
    
            @Override
            protected void onProgressUpdate(String... strings)
            {
                uploadSeekBar.setProgress(uploaded);
                updateUploadMessage(files.size());
                Toast.makeText(Upload.this, strings[0], Toast.LENGTH_LONG).show();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one task to create an application in which some data is there
Imagine a web-application storing some data-resource with some id which stores three attachment (e.g.
There are some applications in Silverlight 3 and WPF which communicate with data web
My application has some data which I would like to keep secure. I have
C# - Winforms - SQL Server i am building an application which displays some
I'm currently writing an iPhone application which gets some data from the user and
I developed an Web application which reads some data from the files from different
I have an application which gets some data from a remote database. I use
I have a Java web application which stores some data in the session. The
I'm developing an application under C# to read some data from a hardware which

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.