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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:24:57+00:00 2026-05-27T18:24:57+00:00

I want to show a progress bar in my activity which contains code to

  • 0

I want to show a progress bar in my activity which contains code to test server connection using socket. I want my progress bar to be visible only when sending data to server. As soon as i got reply from server, the progress should be dismissed and shows Alert box with message “Server busy”. but in my screen the progress bar is visible after getting reply from server.Here is my code .

 public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            mProgress = (ProgressBar) findViewById(R.id.progressBar1);
            mProgress.setProgress(0);
            checkdb();
        }
    private void checkdb() {        
            String message = "";
            try {

                serverIpAddress = InetAddress.getByName("192.168.1.133");

                Log.d("TCP", "C: Connecting...");
                socketObject = new Socket(serverIpAddress, 8221);
                String str = "hi";
                try {
                    Log.d("TCP", "C: Sending: '" + str + "'");
                    PrintWriter out = new PrintWriter(new BufferedWriter(
                            new OutputStreamWriter(socketObject.getOutputStream())), true);
                    out.println(str);

                    inputStream = socketObject.getInputStream();

                    inputDataStream = new DataInputStream(inputStream);

                    message = inputDataStream.readUTF();
                    Log.d("TCP", "C: Reply: '" + message + "'");
                } 
                catch(IOException e)
                {

                    Log.e("TCP", "S: Error", e);
                }catch (Exception e) {

                    Log.e("TCP", "S: Error", e);
                }

                finally {

                    socketObject.close();
                    Log.e("TCP", "S: Error");
                }

            } catch (UnknownHostException e) {
                // TODO Auto-generated catch block
                Log.e("TCP", "C: UnknownHostException", e);
                e.printStackTrace();
            } 
            catch(IOException e)
            {

                Log.e("TCP", "S: Error:", e);

             //Code to show Alert box with message "IOException"

            }
        }

so what should be done to have my progress bar to be visible before i get reply from server. If i get reply, the progress bar should be dismissed.
Any one please help 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-05-27T18:24:58+00:00Added an answer on May 27, 2026 at 6:24 pm

    Here is how I have implemented progressbar while authenticating a user using AsyncTask. See if this can help you

            private class LoginTask extends AsyncTask<String, Integer, Boolean>{
        private final ProgressDialog dialog = new ProgressDialog(LoginActivity.this);
        public LoginTask(LoginActivity activity) {   
    
        } 
    
        @Override 
        protected void onPreExecute() { 
            this.dialog.setMessage("Please wait.."); 
            this.dialog.setIndeterminate(true) ;
            this.dialog.setCancelable(false);
            this.dialog.show();  
            } 
    
    
        @Override
        protected Boolean doInBackground(String... params) {
            try {
                Thread.sleep(5000); //Execute long running task
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
        }
        @Override
        protected void onPostExecute(Boolean result) { 
            if (this.dialog.isShowing()) {            this.dialog.dismiss();         }
            LoginActivity.this.processAuthenticationResult(result.booleanValue());
        }
    
    }   
    

    And called this from my LoginActivity as below

     new LoginTask(LoginActivity.this).execute(new String[]{userName, password});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to show upload progress bar for my uploads using servlet. I tried
I want to show progress with jquery ui progress bar when an ajax request
I want to show a progress bar in background of image view is it
Here is the problem: I want to show a progress bar (just as a
I want to show a progress bar (like wget) how do i keep writing
In my application I want to display the progress bar 1000msec. I am using
i'm using ASIHTTPRequest in asynchrone mode and i want to show an Activity Indicator
I want to show the progress bar during web service call. I called progress
I have created an activity in which I have created a progress bar as
I want to show a progress bar while my iPhone app is uploading an

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.