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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:49:59+00:00 2026-05-27T03:49:59+00:00

I have the following Code for a Button, which i want to built up

  • 0

I have the following Code for a Button, which i want to built up a Socket Connection and then try to send data over the Network. When i have no Server for the Socket it takes a few seconds before the App recognizes and i get an error. In this time the App do nothing (as u could expect) to have a simple Notification for the User to show him the App is not broken, i want to bring up a little ProgressBar.

private void sendButtonListener(Button sendButton, final String server,
        final int port) {
    sendButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            refreshInput();

            showDialog(DIALOG_CONNECTING);
            //Getting the SocketConnection and try to send the Data
            attempToSendXML(builder, profilename);
            dismissDialog(DIALOG_CONNECTING);
        }
    });
}

My Problem is that it seems that the showDialog() Method is brings up the ProgressBar after the onClick(View v) Method is finished. So for my example it shows just nothing (it just hangs until the the attempToSendXML() method is finished), because i close the Dialog after i tried to send the Data.

I hope u guys get my Point and can help me. I’ve been looking around for 2 hours now and really don’t get it …

  • 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-27T03:49:59+00:00Added an answer on May 27, 2026 at 3:49 am

    You should not block the UI thread with a long operation like attempToSendXML().

    Instead you should use an AsyncTask. The AsyncTask should be the solution to your problem as well.

    See here and here.

    The AsyncTask has an onPreExecute()-method where you show up your dialog. attempToSendXML() will then be executed in the method doInBackground and the dialog is closed in the method onPostExecute of the AsyncTask. By doing it this way you do not block the UI-Thread (and get no ANR exception) and the progress dialog shows a long as the operation is working in the background.

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

Sidebar

Related Questions

I have written following code which generates a browse and upload button.i want to
I have the following code -(IBAction)ATapped:(id)sender{ //want some way to hide the button which
I have following code snippet in jquery.In which,I want to animate each element of
I have these following code in which I want to enable 2nd hover state
I have the following code which worked before. Then after I started working on
I have the following code which i am using document.location.search in it.. I want
I have the following code bound to the click event of a button: function
I have the following css code. button.png is image where 3 button states are
I have following Code Block Which I tried to optimize in the Optimized section
I have the following unorderered list code which displays the list below: <ul> <li

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.