OnPostExecute Method is Executing before Doinbackground Fetching Data from Server To Local

℡╲_俬逩灬. 提交于 2019-12-25 15:55:05

问题


  1. In my Android async task class, I'm fetching data from an Azure server to local database inside DoinBackground method

  2. But before finishing the DoinBackground method, it's executing the OnPostExecute method

  3. Inside OnPostExecute method I am disabling the ProgressBar

Help me to solve this issue.

My code:

public class AsyncTaskSync_UserGroupMappingTableClass extends AsyncTask<String, String, Boolean>
{
      {

       @Override
       protected void onPreExecute()
       {
           super.onPreExecute();
       }

       @Override
       protected Boolean doInBackground(String... values)
       {
           try
           {
                mToDoTable_Form5_SPINNER_DataTable456_ServerAzure
                                .execute(new TableQueryCallback<FormsObjectTable2TaskHopsSPinnerValues>() {
                                    public void onCompleted(List<FormsObjectTable2TaskHopsSPinnerValues> result, int count, Exception exception, ServiceFilterResponse response) {
                       if (exception == null) {
                          if (!result.equals("")) {
                              for (int i = 0; i < result.size(); i++) {
                                  /*Table 5 SPinner Data Table*/
                                  IdValue_TableValue5 = result.get(i).getId();
                                  ImeiStringval1_TableValue5 = result.get(i).getImeINumberValOne();
                                  Spinner_IDStringVal1_TableValue5 = result.get(i).getSpinner_id_StringOne();
                                  Spinner_data_StringVal1_TableValue5 = result.get(i).getSPinner_data_Value_StringOne();
                                  Log.i("From SErver DataBase", " Spinner : " + ImeiStringval1_TableValue5 + " : " + Spinner_IDStringVal1_TableValue5 + " : " + Spinner_data_StringVal1_TableValue5);
                                  Asynxfor_DATAinsert5_SpinnerTable(IdValue_TableValue5, ImeiStringval1_TableValue5, Spinner_IDStringVal1_TableValue5, Spinner_data_StringVal1_TableValue5);
                              }
                          } else {
                              Log.i("Data Retrieval Not Found", "No Data In Server For Specific IMEI......!");
                          }
                     } else {
                          Log.i("SOme Exception", "Data Retrieval From Server FORMTABLE1 Data......!");
                          exception.printStackTrace();
                     }
                 }
           });
        }
        catch (Exception e)
        {
            e.printStackTrace();;
            Log.i("Data Retrieval", "Exception Occur......!");
        }

        // PrgDialog.dismiss();
        return null;
    }

    @Override
    protected void onPostExecute(Boolean results)
    {
        try
        {
            Log.i("DONE ", "Data Sync Done Successfully 5 Spinner Values");
            PrgDialog.dismiss();
        }
        catch (Exception e)
        {
            e.printStackTrace();
            Log.i("Exception ", "Post Excecute");
        }
    }
};

Edit 1

My Logcat message:

// From OnPostExecute first Executing also disabling the Progressbar
DONE: Data Sync Done Successfully Form Master 1 

// From Doinbackground
From Server database

回答1:


The requests you are doing inside doInBackground are made asynchronusly that's means that doInBackground is already execute before you get the TableQueryCallback. In other words It's a thread which is launching another thread. I think you do not need to surround it in an AsyncTask, you could handle your respond on TableQueryCallback.onCompleted() with a Handler or an Interface.



来源:https://stackoverflow.com/questions/36547136/onpostexecute-method-is-executing-before-doinbackground-fetching-data-from-serve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!