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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:32:01+00:00 2026-05-23T09:32:01+00:00

For the past few days, I haven’t been able to solve an issue with

  • 0

For the past few days, I haven’t been able to solve an issue with my dialog box. I am running a thread to show the dialog box for 5000ms and removing it. and I am trying to show a toast(“SUCCESS”). The problem is I am getting the dialog box for the second time also. I am new to android development and I need to solve this with Async Task so that I can delay the second thread and show a alert dialog.builder with a positive button instead of toast. I goggled a lot but I confused to to implement this

Here I am sending my credentials to server and while sending I am showing a progress dialog box for 5000ms and I want to have a separate thread in order to show the dialog.builder with a positive button.( When the user get a response in the logcat for that I should check the responsecode==1 or not from the logcat to show the builder)

plz someone help me to solve this with some code snippet if possible.

Thanks in advance.

this is the code where I need to implement Async task

Button signin = (Button) findViewById(R.id.regsubmitbtn);
    signin.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // showDialog(0);
            t = new Thread() {
                public void run() {
                    register();
                    try {
                        while (counter < 2) {
                            showmsg(0);
                            Thread.sleep(5000);
                            removeDialog(0);
                            // Toast.makeText(Register.this, "Registerd", Toast.LENGTH_LONG).show();
                            showmsg(1);
                            // toast.show();

                            Thread.sleep(1000);

                        }

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            };
            t.start();
        }
    });

}

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case 0: {
        ++counter;
        dialog = new ProgressDialog(this);
        if (counter == 1) {
            dialog.setMessage("Registering...");
        }
        else {
            String resultsRequestSOAP = "";
            if (Log.v("TAG", String.valueOf(resultsRequestSOAP)) == 1)
                ;
            {
                Context context = getApplicationContext();
                CharSequence text = "Registerd";
                int duration = Toast.LENGTH_LONG;

                Toast toast = Toast.makeText(context, text, duration);
                toast.show();
            }
        }
        dialog.setIndeterminate(true);
        dialog.setCancelable(true);
        return dialog;
    }
    }
    return null;
}

public void showmsg(int actionsToBePerformedOnScreen) {
    Message msg = new Message();
    msg.what = actionsToBePerformedOnScreen;
    handler.sendMessage(msg);

}

public Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
        case 0:

            showDialog(0);

            break;

        case 1:
            // clear all images in the list
            removeDialog(0);
            break;

        }

    };
};
  • 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-23T09:32:01+00:00Added an answer on May 23, 2026 at 9:32 am

    Easy: show dialog onPreExecute, register() in doInBackground and hide dialog in onPostExecute. Finally, do new RegisterTask().execute() in your onclick.

     private class RegisterTask extends AsyncTask<Void, Void, Boolean> {
      private final ProgressDialog dialog = new ProgressDialog(YourClass.this);
    
      protected void onPreExecute() {
         this.dialog.setMessage("Signing in...");
         this.dialog.show();
      }
    
      protected Boolean doInBackground(final Void unused) {
         return Main.this.register(); //don't interact with the ui!
      }
    
      protected void onPostExecute(final Boolean result) {
         if (this.dialog.isShowing()) {
            this.dialog.dismiss();
         }
         if (result.booleanValue()) {
         //also show register success dialog
         }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to solve a mystery the past few days as to why
For past few days I had been working with MVC... I have to show
I've been teaching myself how to use jquery the past few days, haven't used
For the past few days I have been trying to play any sound over
There have been several questions over the past few days about the proper use
I have been working on learning the Android NDK the past few days, but
I've been using Sublime text 2 for the past few days, and I have
For the past few days I've been working on an online game, a 2-player
I've been asking a question or two over the past few days of working
I've been fiddling with Redmine in the past few days and not 100% happy

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.