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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:33:23+00:00 2026-05-17T01:33:23+00:00

I have an AsyncTask that get info from the web. Sometimes the connection fails

  • 0

I have an AsyncTask that get info from the web. Sometimes the connection fails and the AsyncTask processdialog is running forever.

In the doInBackground I have a check in the end if my catched info are empty and if this is the case, it should appear Positive button/Negative button, but this is not happening. The dialog is just running.

How can I check if an AsyncTask is taking too long time (Maybe 5 seconds) and dismiss the dialog?

Code snippet (doInBackground):

 //orders is my ArrayList<Order> object, from my own Order class.
 if(orders==null) {
                pdia.dismiss();
                AlertDialog.Builder alt_bld = new AlertDialog.Builder(ctx);
                alt_bld.setMessage("Try agin?")
                .setCancelable(false)
                .setPositiveButton("Try again", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                    button_refresh.setVisibility(View.GONE);

                     new ListTask().execute(null, null , null);


                }
                })
                .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
                }

                });
                AlertDialog alert = alt_bld.create();
                alert.setTitle("Connection failed!");
                alert.show();
            }
            else {
                return orders;
            }

Thanks in advance and tell me if you need more info!

  • 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-17T01:33:24+00:00Added an answer on May 17, 2026 at 1:33 am

    Instead of checking your result in doInBackground() you can get the value from the process and check it in onPostExecute(), like this:

    protected void onPostExecute(ArrayList<Order> localOrders){
        super.onPostExecute(localOrders);
        if (localOrders==null) {
           // Paste the positive and negative DialogListeners here 
           // and dismiss the dialog.
        }
    }
    

    The result from your doInBackground() process passes into onPostExecute‘s parameter, thence you can check if your ArrayList object is empty or not.

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

Sidebar

Related Questions

I have an activity that starts with an AsyncTask to check the connection to
I have a class that extends AsyncTask , which fetches the gps cordinates from
I have a class that extends AsyncTask. In the doInBackground() method, I connect to
I have a listview that's populated by rows that get their data from a
I have problem with asynctask on doInBackground because I get a runtime error this
In my app i have a processDialog (using AsyncTask) and at doInbackground it fetches
First, I have a class that extends AsyncTask. Then in the doInBackground() method, I
I have an AsyncTask, that fills a custom List with parsed data from Internet.
I have an AsyncTask that much many rss info, and then applying it to
I have an Asynctask set up to pull icy metadata from shoutcast streams that

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.