Is there Background worker in android? I used AsyncTask suggested in this topic but my progress dialog not show

99封情书 提交于 2020-01-03 02:00:08

问题


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.

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


回答1:


Try this:

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;
        }   
    } 

and execute like this:

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

Hope it Helps!!



来源:https://stackoverflow.com/questions/17969415/is-there-background-worker-in-android-i-used-asynctask-suggested-in-this-topic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!