title: asynctask working in emulator with api 24 and not working in real device with api 28
body: <p>i am using asynctask to fetch data from my hosted web page using the default java httpurlconnection library and apparently the doinbackground method does not execute on my android 9 device but i can receive the json response when tested with emulator api 24. also i declared internet permission in the manifest and i have firebase woking fine, so no internet problem. is there any explanation for this situation? is there any solution while keep using asynctask with httpurlconnection? please help, i have to present my app in two days.</p>
  <p>sendDataAsync.class</p>
  <pre><code>package com.example.control;
  
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  import java.io.OutputStream;
  import java.io.OutputStreamWriter;
  import java.net.MalformedURLException;
  
  import java.net.HttpURLConnection;
  import java.net.URL;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.nio.charset.StandardCharsets;
  
  import android.os.AsyncTask;
  
  class sendDataAsync extends AsyncTask&lt;String , Void , String&gt;{
  
              private AsyncResponse delegate = null;
              private String serverURL, responsemsg = &quot;Not connected to host&quot;,entries;
  
              public sendDataAsync(String name, String prename, String email, String gender, String password, String cfirmpassword) {
                  entries  = &quot;name=&quot;+name+&quot;&amp;prename=&quot;+prename+&quot;&amp;email=&quot;+email+&quot;&amp;gender=&quot;+gender+&quot;&amp;password=&quot;+password+&quot;&amp;cfirmpassword=&quot;+cfirmpassword;
                  serverURL = &quot;http://iotcontrol.atwebpages.com/Register.php&quot;;
              }
  
              public sendDataAsync(String email, String password) {
                  entries  = &quot;password=&quot;+password+&quot;&amp;email=&quot;+email;
                  serverURL = &quot;http://iotcontrol.atwebpages.com/Login.php&quot;;
              }
  
              public void setDelegate(AsyncResponse del){
                  this.delegate = del;
              }
  
              @Override
              protected String doInBackground(String... params) {
                  try {
                      //entries = URLEncoder.encode(entries,&quot;utf-8&quot;);
                      URL url = new URL(serverURL);
                      HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                      conn.setReadTimeout(10000);
                      conn.setConnectTimeout(15000);
                      conn.setRequestMethod(&quot;POST&quot;);
                      conn.setRequestProperty( &quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;);
                      conn.setRequestProperty( &quot;charset&quot;, &quot;utf-8&quot;);
                      conn.setDoInput(true);
                      conn.setDoOutput(true);
  
                      OutputStream os = conn.getOutputStream();
  
                      BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8));
                      writer.write(entries);
                      writer.flush();
                      writer.close();
                      os.close();
  
                      InputStream is = conn.getInputStream();
                      BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
                      String inputLine;
                      StringBuilder sb = new StringBuilder();
                      while ((inputLine = reader.readLine()) != null) {
                          sb.append(inputLine);
                      }
                      reader.close();
                      is.close();
                      conn.disconnect();
                      responsemsg = sb.toString();
  
                  } catch (MalformedURLException e) {
                      e.printStackTrace();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
                  return responsemsg;
              }
  
              @Override
              protected void onPostExecute(String result) {
                  delegate.processFinish(result);
              }
  
          }
  </code></pre>
  <p>in my activity i have this</p>
  <pre><code>  public void insertData() {
      sendDataAsync sendPostReqAsyncTask = new sendDataAsync(nameValue, prenameValue, emailValue, genderValue,passwordValue,cfirmpasswordValue);
      sendPostReqAsyncTask.setDelegate(this);
      sendPostReqAsyncTask.execute();
    }
  /*
  for some reason i cant access logcat so i just have a textview and print the response to it
  
  and while on the emulator api24 i have the text view: {&quot;ok&quot;:false,&quot;message&quot;:&quot;invalide data&quot;}
  but on my android 9 phone i have the text: Not connected to host
  */
    public void processFinish(String output) {
      TextView txt = (TextView)findViewById(R.id.textView3);
      txt.setText(output);
    }
  </code></pre>