title: How to use Asynchronous and onPostExecute to send value to PHP and get Response
body: <p>How to send value to php page using <strong>Asynchronous</strong> with <strong>HttpRequest</strong> and get a response, then do something with it using <strong>OnPostExcute</strong> for example.</p>
  
  <p><strong>Java</strong> :</p>
  
  <pre><code>private class MyAsyncTask extends AsyncTask&lt;String, Integer, Double&gt;{
  
      @Override
      protected Double doInBackground(String... params) {
          // TODO Auto-generated method stub
          postData(params[0]);
          return null;
      }
  
      protected void onPostExecute(Double result){
          pb.setVisibility(View.GONE);
          // Do something with the response here
          // ....
      }
  
      public void postData(String valueIWantToSend) {
          // Create a new HttpClient and Post Header
          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost("__url_to_file.php");
  
          // Add your data
          List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
          nameValuePairs.add(new BasicNameValuePair("myHttpData", valueIWantToSend));
          httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  
          HttpResponse response = httpclient.execute(httppost);
      }
  
  }
  </code></pre>
  
  <p><strong>PHP</strong> :</p>
  
  <pre><code>&lt;?php
      // return the value back to the app
      echo $_POST["myHttpData"];
  
  ?&gt;
  </code></pre>