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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:01:25+00:00 2026-05-25T17:01:25+00:00

I have my Asyntask structure as: private class GetMyFlights extends AsyncTask<String, Void, Integer> {

  • 0

I have my Asyntask structure as:

private class GetMyFlights extends AsyncTask<String, Void, Integer> {       
    private ProgressDialog dialog;  

    public GetMyFlights(ListActivity activity) {}

    protected void onPreExecute() {
        if(mFirstOpen){
            mFirstOpen = false;
            dialog = new ProgressDialog(mCtx);
            this.dialog.setMessage(getResources().getString(R.string.common_getting_data));
            this.dialog.show();
        }
        }       

    @Override
    protected Integer doInBackground(String... params) {
        return getData();
    }       

    @Override
    protected void onPostExecute(Integer result) {  
        super.onPostExecute(result);    
        //if(mFinishGettingData){  //global variable 
            mFinishGettingData = false;
            switch(result){
                case 0:
                    //...                   
                break;
                case 1:
                    //...
                break;
                case 2:             
                    //...
                break;

            }
        //}         
    }
}

And my method getData:

private int getData() {     
    try{
        myFlightsA = new FlightAdapter(this, R.layout.row_myflight, WithingsAPI.getInstance().getFutureFlights());
        //mFinishGettingData = true;
        if(myFlightsA != null)
            return 0;
    }catch(NetworkConnetionException e){
        if(e.getMessage().equals(NetworkConnetionException.ERROR_CONNECTION))
            return 1;
        else if(e.getMessage().equals(NetworkConnetionException.NOT_LOGGED)){
            Log.d(TAG, "Not Logged");
            return 2;
        }
    }catch(Exception e){
        Log.d(TAG, e.toString());
    }       
    return 3;
}

But I dont know if I am doing something wrong, as sometimes the Task work as expected but sometimes appears the dialog as getData returns 3 and afterwards 1.

I have thought about using a global variable mFinishGettingData to notify the ending of the network working. And also return 4 instead of 3 so then afterwards the switch doesnt match none.

  • 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-25T17:01:25+00:00Added an answer on May 25, 2026 at 5:01 pm

    There is only one way this AsyncTask can return 3.

    Your FlightAdapter throws an error and the exception type does not match any of the if..else if inside the catch block.

    if(e.getMessage().equals(NetworkConnetionException.ERROR_CONNECTION))
            return 1;
        else if(e.getMessage().equals(NetworkConnetionException.NOT_LOGGED)){
            Log.d(TAG, "Not Logged");
            return 2;
        }
    

    I suggest you log the exception

    i:e Log.e(TAG, e.getMessage().toString);
    

    right before your if block starts inside you catch block and check to see what kind of exception is it throwing.

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

Sidebar

Related Questions

I have this AsyncTask: private class GetMyFlights extends AsyncTask<String, Void, Integer> { private ProgressDialog
I have this code fragment: public static class ExportDatabaseFileTask extends AsyncTask<String, Void, Boolean> {
I have a common class say for eg Class A which extends AsyncTask and
I have an Activity Class with an inner protected class that extends AsyncTask. I
I have a class which extends AsyncTask, which is intended to serve as a
friends, i am using following code inside asyncTask public class AsycLoaderFromDbAndMapInjector extends AsyncTask {
I have an interface class public interface AsyncTaskExecuteCommand { public Object executeCommand(String jsonLocation) throws
I have a service, that requests another class, which launches an AsyncTask Service->Weather Class->Execute
I have a strangle behavior when implementing AsynTask and ProgressDialog. When i download small
In my Activity I use a class which extends from AsyncTask and a parameter

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.