doInBackground 메서드에서 JSONArray를 읽고 사용자 지정 Items (ArrayList)의 ArrayList를 반환하는 AsyncTask를 만들었습니다. 이것 전에 onPostExecute 메서드에서 AsynchronousTask에있는 ArrayList를 Main 스레드의 다른 ArrayList로 옮긴다.하지만 AsyncTask가 끝나지 않고 여전히 작동하고 있다고 생각한다. 여기AsyncTask는 onPostExecute 메서드로 끝나지 않습니다.
AsyncTask를 : 여기에
private class ReadJSONTask extends AsyncTask<Void, Void, ArrayList<Item>>{
@Override
protected ArrayList<Item> doInBackground(Void... params) {
// TODO Auto-generated method stub
ArrayList<Item> auxList = new ArrayList<Item>();
LoadData(auxList); //Method that reads JSON and load information in the ArrayList
return auxList; // Return ArrayList
}
@Override
protected void onPostExecute(ArrayList<Item> result) {
// TODO Auto-generated method stub
Log.i("OnPostExecute", String.valueOf(result.size())); //The size of the array
listMain = result; // Move the data of the AsyncTask to the main Thread
Log.i("OnPostExecute", String.valueOf(listaComic.size())); //The size of the ArrayList I use in the Main Thread
}
}
하여 메인 스레드에서 AsyncTask를 위해 전화 : 내가 onPostExecute의 모든 로그인 볼 로그에서
if (isOnline()){ //Return true if there is internet connection
ReadJSONTask task = new ReadJSONTask();
task.execute();
Log.i("Main Thread - listMain Size", String.valueOf(listMain.size())); //Never executed
//This for loop its only for debug purposes, never executed
for (Item item : listMain){
Log.i("Items", item.toString());
}
}
여기에 내 코드를 삽입() 메서드가 인쇄되지만 주 스레드에서는 아무것도 표시되지 않습니다.
나는 그것을 해결하기 위해 오류이고, 내가 이일 거기에 노력하고있다 및 StackOverflow의 여기, 포럼에서 검색 모르고 내가 그 문제를 해결 할 수 없습니다 S
Asynctask에 대한 또 다른 알고리즘이 개선되었으며 지금은 작동합니다.이 강의를 가르쳐 주셔서 감사합니다.이 기능은 첫 번째 AsyncTask이고 이에 대한 올바른 접근 방법이 없습니다. 감사 :) – SekthDroid