未调用PreExecute方法的Android Asynctask

时间:2012-12-10 11:24:24

标签: android android-asynctask progressdialog

我希望在调用ProgressDialog时启动onPreExecute(),但它无效。

Homeactivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //switch condtion...
    case R.id.buttontime :                
        new FlightListTask().execute("");
        break:  

}

public class FlightListTask extends AsyncTask<String,ArrayList<HashMap<String, String>>, ArrayList<HashMap<String, String>>> {

    protected String onPreExecute(String temp) {
        progresdialoglistview=ProgressDialog.show(HomeActivity.this, "", "Loading");
        Log.e("onPreExecutive","called"+progresdialoglistview);
        return temp;
    }

    @Override
    protected ArrayList<HashMap<String, String>> doInBackground( String... params ) {
        return flightlist;
    }

    protected void onPostExecute(ArrayList<HashMap<String, String>> flightList) {
        // listview code....
    }

}

2 个答案:

答案 0 :(得分:7)

onPreExecute方法更改为:

  @Override
  protected  void onPreExecute()
  {
      progresdialoglistview=ProgressDialog.show(HomeActivity.this, "","Loading");
      Log.e("onPreExecutive","called"+progresdialoglistview);

  }

onPreExecute()方法不接受任何参数并且具有void返回类型。所以也从onPreExecute

中删除return

答案 1 :(得分:4)

您没有覆盖 onPreExecute,而是重载

onPreExecute不接受任何参数并且不返回任何内容。请改用:

protected void onPreExecute()