问题: 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