0

I have developed an application which contains 3 screens,

One of them is LoginScreen activity, onClick of Login Button it should call a web service

& while returning from web service it should display the ProgressBar.

can anyone help?

Best Regards, Amit

Anup Rojekar
  • 1,093
  • 9
  • 29
  • 1
    This thread will help you http://stackoverflow.com/questions/3893626/how-to-use-asynctask-to-show-a-progressdialog-while-doing-background-work-in-andr – chaitanya Apr 21 '11 at 07:05

3 Answers3

1

This can be easily done using the android.os.AsyncTask. It provides a convenient way to get a progress dialog going and will also help prevent Application Not Responsive errors when a long running web service call would otherwise block the UI thread.

There is decent documentation for it in the android docs and numerous examples around the web.

mmeyer
  • 3,598
  • 1
  • 19
  • 22
1

I think there is no need to use AsyncTask, there is much simpler way to achieve this

final ProgressDialog dialog = ProgressDialog.show                   (this,getResources().getText(R.string.progressbartitle),              getResources().getText(R.string.progressbartext),true,false);

new Thread()
{
    public void run()
    {
         //do you web server call
    }
}.start();

thats all best regards Anup

Anup Rojekar
  • 1,093
  • 9
  • 29
1

Take a look on this:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ProgressDialog  dialog = ProgressDialog.show(FirstScreen.this, "",
                    "Please wait for few seconds...", true);

        // final TextView tv = (TextView)findViewById(R.id.TextView01);           
         final Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                parseData();
            }
        });
          t.start();
         Thread t1 = new Thread(new Runnable() {
            public void run() {

             try {
                t.join();
             } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }  
             mHandler.post(new Runnable() {

                @Override
                public void run() {
            // TODO Auto-generated method stub
                dialog.cancel();
                        //Perform your action after showing dailog here(like showing list) 

                }
            });

            }
        });
        t1.start();        
    }

Hope this will help you.

Dinesh Sharma
  • 11,533
  • 7
  • 42
  • 60