Krishna
Krishna

Reputation: 4984

How to Load the Progress Dialog in android?

I have developed an android application .In that application getting information from web and displayed in the screen.At the time of getting information i want to load a progress dialog to the screen after getting the information i want dismiss the dialog

Please any one help me how to do this with some sample code

Thanks in advance

Upvotes: 0

Views: 462

Answers (2)

pandre
pandre

Reputation: 6725

You need to implement an AsyncTask. Example:

class YourAsyncTask extends AsyncTask<Void, Void, Void> {

    private ProgressDialog progressDialog;

    @Override
    protected void onPreExecute() {
        //show your dialog here
        progressDialog = ProgressDialog.show(this, "title", "message", true, false)
    }

    @Override
    protected Void doInBackground(Void... params) {        
        //make your request here - it will run in a different thread
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        //hide your dialog here
        progressDialog.dismiss();
    }
}

Then you just have to call

new YourAsyncTask().execute();

You can read more about AsyncTask here: http://developer.android.com/reference/android/os/AsyncTask.html

Upvotes: 2

Dmitri Gudkov
Dmitri Gudkov

Reputation: 2123

The point is, you should use two different thread 1st is UI thread, 2nd is "loading data thread" from the 2nd thread you are to post the process state to the 1st thread, for example: still working or 50% is done use this to post data

Upvotes: 0

Related Questions