問題: AsyncTask狀態未指定爲FINISHED,但在執行doInBackground()中的代碼後仍保持RUNNING狀態(應用程序在啓動此任務後運行緩慢,它非常耗時)AsyncTask狀態未指定爲完成
我需要完成。我做錯了什麼?
感謝
代碼(shortend):
MyTask mt;
class MyTask extends AsyncTask<Void, Void, Void> {
int myProgressCount;
@Override
protected void onPreExecute() {
super.onPreExecute();
Toast.makeText(DeviceUARTContext, "onPreExecute Start Progress Bar", Toast.LENGTH_LONG).show();
}
@Override
protected Void doInBackground(Void... params) {
// the code of a task
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
Toast.makeText(DeviceUARTContext, "onPostExecute End Progress Bar",
Toast.LENGTH_LONG).show();
Toast.makeText(DeviceUARTContext, "asynctask status: "+mt.getStatus(), Toast.LENGTH_LONG).show();
// here mt.getStatus() should be "Finished"
}
}
ReadDataBut = (Button) view.findViewById(R.id.button12);
ReadDataBut.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mt = new MyTask();
mt.execute();
}
});
你在問爲什麼你的代碼一直在運行,但你沒有顯示代碼... – 2Dee 2014-10-17 11:35:53