Android“publishProgress”错误

时间:2011-12-02 15:52:29

标签: android android-asynctask

这门课有什么问题?我的progressdialog显示但保持0%然后消失,它永远不会获得百分比更新

public class AsyncLogin extends AbstractAsync {


    public AsyncLogin(Context context, AsyncCallback mAuthcallback) {
        super(context, mAuthcallback);
    }

    @Override
    protected HashMap<String, String> doInBackground(String... args) {
        ...
        publishProgress(50);

        HashMap<String, String> result = html.download();
        publishProgress(75);
        return result;
    }

    protected void onPreExecute() {
        super.onPreExecute();

        this.progressDialog.setMessage(this.context.getString(R.string.please_wait_logging_in));
        this.progressDialog.show();


        publishProgress(25);
    }


    protected void onProgresUpdate(Integer...  progress)
    {
        super.onProgressUpdate(progress);
        Log.v("max", "set progress" + progress[0]);
        this.progressDialog.setProgress(progress[0]);
    }

    protected void onPostExecute(HashMap map) {
        ...
    }

}


abstract class AbstractAsync extends AsyncTask <String, Integer, HashMap>{


    protected Context context;
    protected ProgressDialog progressDialog;
    protected AsyncCallback mAuthcallback;

    public AbstractAsync(Context context, AsyncCallback mAuthcallback) {
        this.context = context;
        this.mAuthcallback = mAuthcallback;

        progressDialog = new ProgressDialog(context);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progressDialog.setCancelable(false);
        progressDialog.setProgress(0);
    }


    protected void onPreExecute()
    {
        super.onPreExecute();
        progressDialog.setMessage(context.getString(R.string.loadingSomething).toString());
        //dialog.show();
    }

    protected void onProgresUpdate(Integer...  progress)
    {
        super.onProgressUpdate(progress);
        Log.v("max", "set progress" + progress[0]);
        progressDialog.setProgress(progress[0]);
    }


    protected void onPostExecute(HashMap result)
    {
        super.onPostExecute(result);
        progressDialog.dismiss();
    }

}

日志永远不会写任何东西

1 个答案:

答案 0 :(得分:3)

您的日志级别是否低于详细信息?

你的方法永远不会达到“publishProgress”吗?

此外,您不应该在onPreExecute中调用publishProgress。第一个是在运行doInBackground的backgorund线程上调用,第二个是在启动bg线程之前由asynctacsk机制调用的。

您是否会发布AbstractAsync代码以防万一?

编辑:

onProgresUpdate

实际上是拼写

onProgressUpdate

免费提示:使用@Override注释确保您实际上覆盖了某些内容