Note that there are some explanatory texts on larger screens.

plurals
  1. POhttpurlconnection is very slow on Android 4.2
    primarykey
    data
    text
    <p>I can succesfully connect, send and receive data by using httpurlconnection. But it takes very long time to load all the data on my phone (Samsung s4, 4.2) and on android 4.2 emulator. But it takes almost 1-2 seconds (which is very fast) to load pics on Android 2.3.x emulator. Faster than my galaxy s4 on http connection.</p> <p>I'm using AsyncTask and my code works fine on both. It is just slow on android 4.2s. I tried removing chunkedStreaming, keep alive, changing timeout values etc. but still no success</p> <p>Here is my code</p> <pre><code>HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("POST"); urlConnection.setDoOutput(true); urlConnection.setDoInput(true); urlConnection.setUseCaches(false); urlConnection.setChunkedStreamingMode(0); urlConnection.setRequestProperty("Connection", "Keep-Alive"); urlConnection.setConnectTimeout(6000); urlConnection.setReadTimeout(6000); urlConnection.setRequestProperty("Content-Type", "multipart/form-data;charset=UTF-8;boundary="+boundary); urlConnection.connect(); </code></pre> <p>Are there any differences between 4.2's and 2.3.x's httpurlconnections? Whats wrong here</p> <p>UPDATE!</p> <p>I tested by using Log.e() to see which line takes most time.</p> <pre><code>///// other staff ////...... Log.e("HTTP","3"); if (isCancelled()) return (null); // don't forget to terminate this method Log.e("HTTP","3"); //Output DataOutputStream outputStream = new DataOutputStream( urlConnection.getOutputStream() ); //Send Passcode Log.e("HTTP","4"); </code></pre> <p>Between 3 and 4, 5-6 second passes on the line </p> <pre><code>DataOutputStream outputStream = new DataOutputStream( urlConnection.getOutputStream() ); </code></pre> <p>UPDATE!!</p> <p>That waiting time (see previous update) is related to the urlConnection.setConnectTimeout(6000);</p> <p>When I make Timeout 1000, then connection responses quickly (waiting 1 second for the line)</p> <pre><code>DataOutputStream outputStream = new DataOutputStream( urlConnection.getOutputStream() ); </code></pre> <p>No idea why this is happening</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload