1

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 !!

Community
  • 1
  • 1
ali shekari
  • 740
  • 1
  • 11
  • 26

1 Answers1

8

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!!

Armaan Stranger
  • 3,140
  • 1
  • 14
  • 24
  • I need to use progress dialog but my progress dialog show after all task end.rendered this is my code : DBAsyncTask dba = new DBAsyncTask(this, xmlCommand); dba.inProcess = true; dba.execute(""); while (dba.inProcess) { try { Thread.sleep(200); ExirDebugger.println("wwwwait"); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } i started progress dialog in onPreExecute but render progress after work ended!!!! – ali shekari Jul 31 '13 at 12:32
  • why are you using thread.sleep()?? don't use that and put dialog.show in OnpreExecute method of asynctask. – Armaan Stranger Jul 31 '13 at 12:37