问题描述
-
在我的Android异步任务类中,我正在从Azure服务器中的数据提取到
DoinBackground
方法
但是在完成 DoinBackground
方法之前,它正在执行 OnPostExecute
方法
But before finishing the DoinBackground
method, it's executing the OnPostExecute
method
内部 OnPostExecute
方法中,我禁用了 ProgressBar
Inside OnPostExecute
method I am disabling the ProgressBar
帮我解决这个问题.
我的代码:
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");
}
}
};
编辑1
我的Logcat消息:
My Logcat message:
// From OnPostExecute first Executing also disabling the Progressbar
DONE: Data Sync Done Successfully Form Master 1
// From Doinbackground
From Server database
推荐答案
您在 doInBackground
内部执行的请求是异步进行的,这意味着 doInBackground
已经在您执行之前获取 TableQueryCallback
.换句话说,这是一个正在启动另一个线程的线程.我认为您不需要将其包围在 AsyncTask
中,您可以使用处理程序或接口在 TableQueryCallback.onCompleted()
上处理响应.
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.
这篇关于在Doinbackground将数据从服务器获取到本地之前,将执行OnPostExecute方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!