アクティビティ クラスの外に AsyncTask を実装しようとしています。問題は、この asynctask クラスのステータスが常に実行中と表示されていることです。どうすれば終了させることができますか?
これは私のアクティビティクラスです
protected void onCreate(Bundle savedInstanceState) {
employeeAsyncTask.execute(new String[] {url});
System.out.println("Status "+employeeAsyncTask.getStatus());
//employeeAsyncTask.cancel(true);
while(employeeAsyncTask.getStatus() == AsyncTask.Status.RUNNING){
}
while (employeeAsyncTask.getStatus()== AsyncTask.Status.FINISHED) {
System.out.println("hereeeeeeeeeeeeee");
ArrayList<Employee> list = employeeAsyncTask.getEmpList();
System.out.println("Size of list "+list);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_capture);
}
これは私の asynctask クラスです
public class FetchEmployeeAsyncTask extends AsyncTask<String, Void, ArrayList>{
private ArrayList<Employee> empList = null;
private boolean done = false;
/**
* @return the done
*/
public boolean isDone() {
return done;
}
/**
* @param done the done to set
*/
public void setDone(boolean done) {
this.done = done;
}
@Override
protected ArrayList doInBackground(String... url) {
// TODO Auto-generated method stub
ArrayList<Employee> employees = null;
for(String employeeUrl : url){
employees = fetch(employeeUrl);
}
return employees;
}
private ArrayList<Employee> fetch(String url) {
// TODO Auto-generated method stub
ArrayList<Employee> employees = null;
String response = null;
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity);
employees = EmployeeXMLParser.XMLfromString(response);
System.out.println("Size in fetch "+employees.size());
//System.out.println("Employee Name :: " + employees.get(0).getFirstName() + " " + employees.get(0).getLastName());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} /*catch (XmlPullParserException e) {
// TODO Auto-generated catch block
System.out.println("Error parsing the response :: " + response);
e.printStackTrace();
}*/
return employees;
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
done = false;
}
@Override
public void onPostExecute(ArrayList employeeList){
setEmpList(employeeList);
System.out.println("in post execxute "+employeeList.size());
done = true;
}
public ArrayList<Employee> getEmpList() {
return empList;
}
public void setEmpList(ArrayList<Employee> empList) {
this.empList = empList;
}
}
onPostExecute() に何を含めるべきかわかりません。