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

2
  • a little research before asking, if you don't mind? Commented Mar 1, 2013 at 11:43
  • alright how do i delete my post? Commented Mar 1, 2013 at 11:52

1 Answer 1

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;
Sign up to request clarification or add additional context in comments.

4 Comments

where do i put the things that i will do in long time?
if i create a seperate class puting the code above how do i implement it? sorry for noobish question
instantiate it then after, call doinbackground like that?
Do your stuff in doInBackground() , you can refer this link http://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.