title: Display Dialog when loading internet
body: <p>I am trying to create a dialog when loading Httprequest. But it load during the i click to intent from last Activity, but not the start of this Activity.</p>
  
  <p>And the dialog just shown in 0.00001sec then dismiss.</p>
  
  <p>Am i implement it wrongly?</p>
  
  <p>Here is my codes</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      HttpPostHandler2 handler = new HttpPostHandler2();
      String URL ="http://xxxxxx";        
      handler.execute(URL);
  }
  
  public class HttpPostHandler2 extends AsyncTask&lt;String, Void, String&gt; {
  
      private String resultJSONString = null;
      private ProgressDialog pDialog;
  
      public String getResultJSONString() {
          return resultJSONString;
      }
  
      public void setResultJSONString(String resultJSONString) {
          this.resultJSONString = resultJSONString;
      }
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
              pDialog = new ProgressDialog(MainActivity.this);
              pDialog.setMessage("Please Wait");
              pDialog.setIndeterminate(false);
              pDialog.setCancelable(false);
              pDialog.show();
      }
  
      @Override
      protected String doInBackground(String... params) {
  
          CredentialsProvider credProvider = new BasicCredentialsProvider();
          credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST,
                  AuthScope.ANY_PORT), new UsernamePasswordCredentials("core",
                  "core1234"));
          String responseContent = "";
  
          HttpClient httpClient = new DefaultHttpClient();
          ((AbstractHttpClient) httpClient).setCredentialsProvider(credProvider);
          HttpPost httpPost = new HttpPost(params[0]);
  
          HttpResponse response = null;
          try {
              // Execute HTTP Post Request
              response = httpClient.execute(httpPost);
              responseContent = EntityUtils.toString(response.getEntity());
          } catch (ClientProtocolException e) {
              // TODO Auto-generated catch block
          } catch (IOException e) {
              // TODO Auto-generated catch block
          }
          setResultJSONString(responseContent);
          // return new JSONObject(responseContent);
          return responseContent;
      }
  
      @Override
      protected void onPostExecute(String result) {
          pDialog.dismiss();  
          super.onPostExecute(result);
          resultJSONString = result;
      }
  }
  </code></pre>