ali shekari
ali shekari

Reputation: 740

AsyncTask not show progress dialog immediate

I used suggestion in this but I have same problem yet. Thanks my friend for suggestion for using AsyncTask but it is not worked for me. What? This is my code :

DBAsyncTask dba = new DBAsyncTask(this, xmlCommand);
    dba.inProcess = true;
    dba.execute("");
    while (dba.inProcess) {
        try {
            Thread.sleep(200);
            println("wwwwait");
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    public class DBAsyncTask extends AsyncTask<String, Void, String> {
    public boolean inProcess;

    public DBAsyncTask(ExirCommandRunner commandRunner,XmlNode xmlCommand) {
        this.commandRunner = commandRunner;
        this.xmlCommand = xmlCommand;

    }

    @Override
    protected void onPostExecute(String result) {
        ExirDebugger.println("onPostExecute");
    }

    @Override
    protected void onPreExecute() {
        showProgress();
    }

    @Override
    protected String doInBackground(String... params) {
    ///my process here 
        closeProgress();
        return null;
    }

Can anyone help me?

Upvotes: 2

Views: 1334

Answers (3)

laalto
laalto

Reputation: 152927

Thread.sleep() blocks the UI thread and therefore the progress dialog cannot run. Remove that and the inProcess polling mechanism. Also, there's a lot of references on using async task with progress dialog.

Upvotes: 3

Armaan Stranger
Armaan Stranger

Reputation: 3140

It should be like:

protected void onPreExecute() {
            super.onPreExecute();
             pDialog = new ProgressDialog(activityContext);
             pDialog.setCancelable(false);
             pDialog.setMessage("Please Wait..");
             pDialog.show();
        }

and

protected void onPostExecute(String file_url) 
        {
            if(pDialog.isShowing())
            {
                pDialog.cancel();
            }
                }

Upvotes: 1

canova
canova

Reputation: 3975

I explained a detailed usage of ProgressDialog in AsyncTask and the solution here: https://stackoverflow.com/a/17527979/1943671

Upvotes: 1

Related Questions