我有一个关于 android 中的 AsyncTask 类的问题,以及为什么它给我一个错误。我在这里定义了一个内部类..
class MyTask extends AsyncTask<String,String,Integer>{
Context context;
ProgressDialog dialog;
MyTask(Context c)
{
this.context = c;
}
//@Override
protected void onPreExecute()
{
dialog = new ProgressDialog(context);
dialog.setMessage("Scanning Ports!");
dialog.show();
}
@Override
protected Integer doInBackground(String... params) {
// TODO Auto-generated method stub
for(intBeg = intBeg; intBeg <= intEnd; intBeg++
{
try
{
Socket s = new Socket(strMachine, intBeg);
isConnected += strMachine + " Is Listening On Port: " + intBeg + "\n";
Log.d("PORTSCAN", isConnected);
s.close();
}catch(Exception e){
notConnected += strMachine + " Is Not Listening On Port: " + intBeg + "\n";
//Toast.makeText(getBaseContext(), e.getMessage(), 3000).show();
Log.d("PORTSCAN", notConnected);
}
}
return 1;
}
protected void onPostExecute(Integer... params)
{
}
protected void onProgressUpdate(String... params)
{
}
}
但是,当 doInBackground 完成时,它应该调用 onPostExecute(),而这永远不会发生。即使我尝试在 onPostExecute() 上使用“@Override”注释,它也会给我一个错误,说 onPostExecute 必须覆盖超类方法。我不明白发生了什么!有什么帮助吗?谢谢!