【问题标题】:Problem with call of Methods of AsyncTask调用 AsyncTask 方法的问题
【发布时间】:2011-09-13 07:39:09
【问题描述】:

我正在尝试使用 AsyncTask 更新进度条 我的代码看起来像这样

private class ProgressBar extends AsyncTask<Void, Integer, Integer>
{
 protected Integer doInBackground(Void... params) 
 {
    int a=2;
    for(int i=0;i<=100;i=i+5)
    {
        SystemClock.sleep(1000);
        publishProgress(i);
    }
    return a;
 }

 protected void onProgressUpdate(Integer... item) 
 {
    //int no_of_argruments=item.length;
    tv.setText("Over !!"+item[0]);
    bar.setProgress(item[0]);
 }

protected void onPostExecute()
{
    if(result[0]!=null)
    {
        tv.setText("Hurray !!");
        Toast.makeText(checkThread.this, "Done!", Toast.LENGTH_SHORT)
        .show();
    }
}

但是在 doInBackground() 完成后,我的 onPostExecute() 没有被调用,进度条只是挂到它的最终值。

如何调用 onPostExecute() 方法??

【问题讨论】:

    标签: android asynchronous android-asynctask


    【解决方案1】:

    这是 postExecute() 的正确签名

    protected void onPostExecute (Result result)
    

    你的方法是你自己的方法,AsyncTask 不知道。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-19
      • 2015-09-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-24
      相关资源
      最近更新 更多