I've created a generic AsyncTask. It works fine in background but when I update UI in doInBackground callback of this task, it just hang loading circle of SwipeRefreshLayout multiple times. I need this loading to run smoothly. I'm using AsyncTask as follows
public class backgroundWorker extends AsyncTask<Object, Void, Object>{//params, progress, result
backgroundWorkerCallback callback;
public backgroundWorker(backgroundWorkerCallback _callback) {
this.callback = _callback;
}
@Override
protected void onPostExecute(Object result) {
super.onPostExecute(result);
callback.onPostExecute(result);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Object doInBackground(Object... param)
{
return callback.doInBackground(param);
}
}
backgroundWorkerCallback is an interface
public interface backgroundWorkerCallback {
public Object doInBackground(Object param);
public void onPostExecute(Object result);
}
I'm using this AsyncTask in this way
srlStockReport.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
backgroundWorker bw = new backgroundWorker(new backgroundWorkerCallback(){
@Override
public Object doInBackground(Object param)
{
//fetch data from server
//put some data in in Preference
//Load a RecyclerView from list
return null;
}
@Override
public void onPostExecute(Object result)
{
}
});
bw.execute();
}
});