0

Below is my code: that works fine but dialog not showing.Dialog should open with ASyncTask starts and dismiss with ends.how is is possible to do?


    Public class RootClass
    {
    public ProgressDialog dialog;
    public List methodA(String a)
    ----
    ----

Class childClass extends AsyncTask<Void,Void,Void>
{
    @Override
    protected void onPreExecute() {

        dialog = ProgressDialog.show(RootClass.this,"Please wait", "Message");
    }

    @Override
    protected Void doInBackground(Void... params) {
    ----
    ---
    ---
        List<String> B=methodA(String a);
    -----
    -----

    }

    @Override
    protected void onPostExecute(Void result) {
        dialog.dismiss();
        return;
    }
}

}</pre>
lakhani
  • 128
  • 2
  • 13
  • have you logged the time difference, maybe the Asynctask is getting over very fast – nandeesh Sep 06 '12 at 07:45
  • 1st possibilty : your doInBackground() has a very small task to do... so the dialog appears and dimiss very quickly(unnoticeable).... to check this... try commenting dialog.dismiss() 2nd Possibility: u are not calling the asyncTask properly.... – Aditya Nikhade Sep 06 '12 at 07:48
  • no.. its taking almost 1 and half minute.. – lakhani Sep 06 '12 at 07:48
  • if m not calling asynctask properly , it not go to postexecute , but it goes there and do later process – lakhani Sep 06 '12 at 07:51
  • @lakhani Maybe this [link](http://stackoverflow.com/questions/4538338/progressdialog-in-asynctask) can help you ? – Pillz Sep 06 '12 at 07:52

3 Answers3

0

Your RootClass should extend Activity class

 public class RootClass extends Activity
sinisha
  • 1,013
  • 13
  • 30
0

in the onCreate method. on the very event when you are going to start the async task write

dialog = ProgressDialog.show(RootClass.this,"Please wait", "Message");

you cannot update the ui in the doiin backgroung() metho,,

and later onPostExecute(), dialog.dissmiss;.

Pranav Sharma
  • 692
  • 2
  • 9
  • 22
-1

Instead of using - public ProgressDialog dialog;

Try using-- public Dialog process;

and in Async taks use this code

protected void onPreExecute() 
{
progress = ProgressDialog.show(YourActivity.this, "Please wait",
                "Loading..", true);
}

and

protected void onPostExecute(String result) {
super.onPostExecute(result);
if (progress.isShowing()) {
progress.dismiss();
}

Hope this helps!

Anuj Balan
  • 7,629
  • 23
  • 58
  • 92
acid
  • 1
  • 5