Question: my application - create a gif image from n jpg images.
This method has to read many images, so need a long time. I want to show progressdialog when this method running.
Please help me, any idea or source code example!
Thanks

Answer: 
If you're just doing it on the UI thread (NOT RECOMMENDED) it would look like this:

```
private void myMethodThatTakesALongTime() {
    ProgressDialog progressDialog;
    progressDialog = new ProgressDialog( getActivity() );
    progressDialog.setIndeterminate( true );
    progressDialog.setMessage( "Please Wait..." );
    progressDialog.show();

    // Do expensive operations

    progressDialog.dismiss();
}

```

I would recommend putting all of this into an AsyncTask. It would look like this:

```
private class MyAsyncTask extends AsyncTask<String, String, String> {

    private ProgressDialog progressDialog;

    protected void onPreExecute() {

        //show your dialog before you start

        progressDialog = new ProgressDialog( getActivity() );
        progressDialog.setIndeterminate( true );
        progressDialog.setMessage( "Please Wait..." );
        progressDialog.show();
    }

    @Override
    protected String doInBackground( String... params ) {

        // do expensive operations in here

        return null;
    }

    @Override
    public void onPostExecute( String result ) {

        //dismiss your dialog when done

        if ( progressDialog != null && progressDialog.isShowing() ) {

            progressDialog.dismiss();
        }
    }
}

```

And you would start this off using the following line:

```
new MyAsyncTask().execute( String[] {} );

```
You need to do two things in here.
Firstly use [oncreateDialog](http://developer.android.com/guide/topics/ui/dialogs.html)() method to create your dialoge.
Secondly you should use a [async](http://developer.android.com/reference/android/os/AsyncTask.html) task to do your long running task. while launching async task you can show your dialoge and when you finishes the task and return back to your activity you can dismiss it again.