I am fetching and processing some JSON data in a background thread...even then I can see warning in my log saying that the application is doing too much work in ht ui thread. I cannot understand what is wrong.
Here is my method:
private void getLists1() {
busy =true;
runOnUiThread(()->{
listPD.show();
});
MyAsyncTask1 asyncTask1 = new MyAsyncTask1((String output) -> {
if (!output.equals("failed")) {
runOnUiThread(()->{
listPD.setMessage("getting expense list");
});
JSONObject jsonObject = new JSONObject(output);
JSONArray array = jsonObject.getJSONArray("records_et");
int ii = array.length();
for (int i = 0; i < ii; i++) {
JSONObject jsonObject1 = array.getJSONObject(i);
String id = jsonObject1.getString("id");
String name1 = jsonObject1.getString("name");
int finalI = i;
listDB.insertItem(name1, id);
}
runOnUiThread(()->{
listPD.setMessage("expense list saved");
});
}
});
asyncTask1.executeOnExecutor((AsyncTask.THREAD_POOL_EXECUTOR), "http://webservice");
MyAsyncTask1 asyncTask2 = new MyAsyncTask1(output1 -> {
if (!output1.equals("failed")) {
Log.i("response", "vendor " + output1);
runOnUiThread(()->{
listPD.setMessage("getting vendor list");
});
//vendor list
JSONObject jsonObject12 = new JSONObject(output1);
JSONArray array1 = jsonObject12.getJSONArray("records_vendor");
int ii1 = array1.length();
for (int i = 0; i < ii1; i++) {
JSONObject jsonObject1 = array1.getJSONObject(i);
String id = jsonObject1.getString("id");
String name1 = jsonObject1.getString("name");
int finalI = i;
listDB.insertVendorItem(name1, id);
}
runOnUiThread(()->{
listPD.setMessage("vendor list saved");
listPD.dismiss();
});
}
});
asyncTask2.executeOnExecutor((AsyncTask.THREAD_POOL_EXECUTOR), "http://webservice");
}
I call the method like this;
new Thread(()->{
getLists1();
}).start();
listPD is the progress dialogue...the app starts lagging when I call this function what I am I missing here.