2

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?

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

3 Answers3

3

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.

laalto
  • 150,114
  • 66
  • 286
  • 303
  • thank you! but i need to wait and sleep procedure. my process is complexity and I do not set next state in onPostExecute. i am seeking for solving this problem. – ali shekari Aug 01 '13 at 09:23
1

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

Community
  • 1
  • 1
canova
  • 3,965
  • 2
  • 22
  • 39
1

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();
            }
                }
Armaan Stranger
  • 3,140
  • 1
  • 14
  • 24