AsyncTask没有onProgressUpdate Android

-1 android android-asynctask

看起来这个类没有用,因为它从不发布进度. onPostExecute实际上有效.但是这个课程主要依赖于progressUpdate.

class DoBackgroundStuff extends AsyncTask<String, Integer, String> {

    @Override
    protected String doInBackground(String... a) {

        String rawContactsDl;
        while(true) {

            if (isFinished == true) {
                backgroundStopped = true;
                break;
            }

            //DO SOME STUFF
            publishProgress(1);

            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return "done";
    }

    protected void onProgressUpdate(int progress) {
        Log.i("VERBOSE","onProgress " + progress);
        adapter.notifyDataSetChanged();
    }

    protected void onPostExecute(String result) {
        Log.i("VERBOSE","onPosts " + result);
        adapter.notifyDataSetChanged();
    }

}
Run Code Online (Sandbox Code Playgroud)

mar*_*inj 8

你的onProgressUpdate看起来应该是这样的:

protected void onProgressUpdate (Integer... values)
Run Code Online (Sandbox Code Playgroud)

总是使用@Override来捕捉这样的错误


laa*_*lto 5

onProgressUpdate()签名是错误的.它应该是

protected void onProgressUpdate(Integer... progress)
Run Code Online (Sandbox Code Playgroud)