是否有Android的后台工作?我用的AsyncTask本主题中建议,但我的进度对话框不显示我的、我用、本主题、对话框

2023-09-07 03:20:30 作者:大路朝天,咱俩各走一边。

是否有任何Android的后台工作!我用的进展this

Is there any background worker in android! I used progress dialog in this

但没有解决这个建议。我需要显示等待对话框,我的过程结束后,做其他处理。

but no resolve for this suggested. I need to show a wait dialog and after my process end, do other process.

我用的AsyncTask本主题中建议,但我的进度对话框不会立即显示尚未!!

I used AsyncTask suggested in this topic but my progress dialog not show immediately yet !!

推荐答案

试试这个:

class myAsyncTask extends AsyncTask<Void, Void, Void>    {
        Context context;
        myAsyncTask(Context context)    {
             this.context=context;           
        }
        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            //Do stuff that you want after completion of background task and also dismiss progress here.
        }
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            //create and show progress dialog here
        }
        @Override
        protected Void doInBackground(Void… arg0) {
            //background task here
            return null;
        }   
    } 

和执行是这样的:

myAsyncTask myWebFetch = new myAsyncTask();
                myWebFetch.execute();

希望它帮助!