0

How do i make ProgressDialog that will show while my method doing a bit while job? I know there's a lot related question to this but i don't understand the answers. A separate thread is a good approach or not? My method is downloading some datas from the Internet

Please provide me a quite detailed answer of how do i make this. A separate class will be great

Any answer and comment will be appriciated

user1708134
  • 643
  • 1
  • 9
  • 21

1 Answers1

2

Hey try the following code it may helpful :

  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

new TheTask().execute();
 }

private class TheTask extends AsyncTask<Void, Void, Void>{

 @Override
protected void onPreExecute()
{
    super.onPreExecute();
    pDialog = new ProgressDialog(YOUR_ACTIVITY_CLASS_NAME.this);
    pDialog.setMessage("Please Wait");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(false);
    pDialog.show();
}

@Override
protected Void doInBackground(Void... params) {
    authenticate(); // method that calls the API via SOAP
    authenticateReal(); // method that handles the response
    return null;
}

@Override
 protected void onPostExecute(String str)
 {
    // Dismiss the dialog once finished
    pDialog.dismiss();  
  }
 }

Define pDialog before you call it:

   ProgresDialog pDialog;
androidgeek
  • 3,440
  • 1
  • 15
  • 27