title: show ProgressDialog onActivityResult
body: <p>I have two activities the first one load url(simple webview) and the second one get the id for url from listview then call back the first activity to load the url.
  I'm use <code>onActivityResult()</code> method in the first activity to get the extra data(url id).
  My problem is when I want to show the ProgressDialog in the first Activity in method <code>onActivityResult()</code> after choose item from ListView in second activity I got a ProgressDialog but it just shows for seconds (very quickly) then disappear before complete the load for url(WebView)</p>
  
  <p>This is the code for the tow activities I hope help me.</p>
  
  <pre><code>public class LibActivity extends Activity {
  
  private ImageButton btnCategoriesList;
  
  public static final int BOOK_CATEGORY_REQUEST_CODE = 1;
  
  private WebView webView;
  
  public ProgressDialog dialog;
  private Handler handler;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.lib);
  
      handler = new Handler();
      dialog = ProgressDialog.show(this, "Loading", "Please wait", true, false);
  
      DisplayMetrics displaymetrics = new DisplayMetrics();
  
      webView = (WebView) findViewById(R.id.categoryWebView);
      webView.setWebViewClient(new CategoryItemWebViewClient());
      webView.getSettings().setJavaScriptEnabled(true);
      webView.loadUrl("http://maktabati.mobi/V3/store.php?catid=" + "91");
  
      btnCategoriesList = (ImageButton) findViewById(R.id.btn_category_list);
  
      btnCategoriesList.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              showBooksCategories();
          }
      });
  }
  
  /**
   * 
   */
  protected void showBooksCategories() {
      Intent intent = new Intent(getApplicationContext(), BooksCategoriesActivity.class);
      startActivityForResult(intent, BOOK_CATEGORY_REQUEST_CODE);
  }
  
  /**
   * 
   * @author Jamil
   * 
   */
  private class CategoryItemWebViewClient extends WebViewClient {
      @Override
      public boolean shouldOverrideUrlLoading(WebView view, String url) {
          if (url.contains("book")) {
              String bookId = url.substring(12);
              Intent intent = new Intent(getApplicationContext(), BookDetailActivity.class);
              intent.putExtra("BOOK_ID", bookId);
              startActivity(intent);
              view.stopLoading();
          }
          return super.shouldOverrideUrlLoading(view, url);
      }
  
      @Override
      public void onPageFinished(WebView view, String url) {
          super.onPageFinished(view, url);
          dialog.dismiss();
      }
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
      if (requestCode == BOOK_CATEGORY_REQUEST_CODE) {
          if (resultCode == RESULT_OK) {
              dialog = ProgressDialog.show(this, "Loading", "Please wait", true);
              new Thread() {
                  public void run() {
                      webView.loadUrl("http://maktabati.mobi/V3/store.php?catid=" + data.getStringExtra("CATEGORY_ID"));
                      handler.post(new Runnable() {
                          @Override
                          public void run() {
                              dialog.dismiss();
                          }
                      });
                  }
              }.start();
  
          }
      }
      super.onActivityResult(requestCode, resultCode, data);
  }
  </code></pre>
  
  <p>the second activity</p>
  
  <pre><code>public class BooksCategoriesActivity extends Activity {
  
  ItemsCategoriesAdapter adapter;
  ArrayList&lt;Category&gt; lstCategory;
  Handler handlerProgressDialog;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      setContentView(R.layout.books_categories_list);
      handlerProgressDialog = new Handler();
      CategoryHandler handler = new CategoryHandler();
      ParserCreater parserCreater = new ParserCreater(handler);
      parserCreater.parse("http://maktabati.mobi/V3/getCategories.php");
      lstCategory = handler.getLstCategory();
      final ListView listView = (ListView) findViewById(R.id.categories_list);
      adapter = new ItemsCategoriesAdapter(lstCategory);
      listView.setAdapter(adapter);
      listView.setTextFilterEnabled(true);
  
      listView.setOnItemClickListener(new OnItemClickListener() {
  
          @Override
          public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, final int position, long arg3) {
              Intent intent = new Intent(getApplicationContext(), LibActivity.class);
              intent.putExtra("CATEGORY_ID", lstCategory.get(position).getId());
              BooksCategoriesActivity.this.setResult(RESULT_OK, intent);
              finish();
          }
      });
  }
  </code></pre>
  
  <p>Thanks</p>