-1

I am struck with this issue where, on getting a successful return from doInBackground, the onPostExecute is just not executed.

I read this StackOverflow answer which said that there is an issue with params. But, I am unable to figure out why. I have been running many AsyncTasks but have never encountered a problem as this. And other similiar SO answers doesn't help either.

Following is my code. Where I get values successfully in companyVO. Please help me solve this.

I feel it is something to do with parameters. Even the @Override annotation on postExecute shows error.

class companyCall extends AsyncTask<Void, Void, ArrayList<CompanyVO.ResultSet>> {


        protected ArrayList<CompanyVO.ResultSet> doInBackground(Void...params) {
            SharedPreferences prefrence = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
            String Token = prefrence.getString("token", "");
            try {
                WebserviceImpl webservices = new WebserviceImpl();
                companyVO = webservices.getAllCompanyINfo(Token, getApplicationContext());

            } catch (Exception e) {
                Log.e("TAG", "Exception", e);
                return null;
            }
            return companyVO;
        }


        protected void onPostExecute(CompanyVO.ResultSet result) {
            if (result != null) {

                Log.e("Done", "done"+result.getName());

            } else {
                Log.e("Error", "Not done");
            }
        }

    }
Shachi
  • 1,858
  • 3
  • 23
  • 41

2 Answers2

3

You missed @Override . So its not the overrided method also you have used different parameters. It should be as .

class CompanyCall extends AsyncTask<Void, Void, ArrayList<CompanyVO.ResultSet>> {
    @Override
    protected ArrayList<CompanyVO.ResultSet> doInBackground(Void...params) {
        SharedPreferences prefrence = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        String Token = prefrence.getString("token", "");
        try {
            WebserviceImpl webservices = new WebserviceImpl();
            companyVO = webservices.getAllCompanyINfo(Token, getApplicationContext());

        } catch (Exception e) {
            Log.e("TAG", "Exception", e);
            return null;
        }
        return companyVO;
    }
    @Override
    protected void onPostExecute(ArrayList<CompanyVO.ResultSet> result) {
        if (result != null) {
            Log.e("Done", "done"+result.getName());
        } else {
            Log.e("Error", "Not done");
        }
    }

}
ADM
  • 20,406
  • 11
  • 52
  • 83
1

Your result is Arraylist, Access it with forloop

class CompanyCall extends AsyncTask<Void, Void, ArrayList<CompanyVO.ResultSet>> {
    @Override
    protected ArrayList<CompanyVO.ResultSet> doInBackground(Void...params) {
        SharedPreferences prefrence = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        String Token = prefrence.getString("token", "");
        try {
            WebserviceImpl webservices = new WebserviceImpl();
            companyVO = webservices.getAllCompanyINfo(Token, getApplicationContext());

        } catch (Exception e) {
            Log.e("TAG", "Exception", e);
            return null;
        }
        return companyVO;
    }
    @Override
    protected void onPostExecute(ArrayList<CompanyVO.ResultSet> result) {
        if (result != null) {
            for(CompanyVO.ResultSet result_:result) {

                Log.e("Done", "done"+result_.getName());
            }
        } else {
            Log.e("Error", "Not done");
        }
    }

}
Akash Sharma
  • 286
  • 1
  • 5