title: Android GPRS network communication delay when receving call
body: <p>I've written an Android code that tries to access a server over the network upon an incoming call.</p>
  
  <p>Network access is executed once an incoming call is received using a BroadcastReceiver with the intent-filer of READ_PHONE_STATE.</p>
  
  <p>Data communication is performed over GPRS.</p>
  
  <p>Using the logcat I've noticed that the data retrieval time from the network has large distribution, ranging from 1sec to 15sec.</p>
  
  <p>Here is the code for sending a HTTP request and waiting for server response</p>
  
  <pre><code>        urlConnection = (HttpURLConnection) url.openConnection();
          Log.i("TIMINGS", "Connected to server.");
          jsonobj.put("id", id);
          String requestContent = jsonobj.toString();
          urlConnection.setDoOutput(true); // Will make a POST HTTP request
          urlConnection.setFixedLengthStreamingMode(requestContent.length());
          urlConnection.setRequestProperty("content-type", "application/json");
          urlConnection.setRequestProperty("Connection", "close");
          System.setProperty("http.keepAlive", "false");
          urlConnection.setDefaultUseCaches(false);
  
          Log.i("TIMINGS", "Sending request...");
          // Write the JSON string to the POST request content
          DataOutputStream out = new DataOutputStream(urlConnection.getOutputStream());
          out.writeBytes(requestContent);
          out.flush();
          out.close();
          Log.i("TIMINGS", "Request sent.");
  
          Log.i("DEBUG", "Connect response code: " + urlConnection.getResponseCode());
  
          // Get the output from the server
          Log.i("TIMINGS", "Extracting data from response...");
          InputStream in = new BufferedInputStream(urlConnection.getInputStream());
          byte[] bytes = getBytesFromInputStream(in);
          if (bytes == null) {
              return null;
          }
          in.close();
          Log.i("TIMINGS", "Response extracted");
      } catch (Exception e) {
          e.printStackTrace();
          return null;
      } finally {
          if (urlConnection != null) {
              Log.i("TIMINGS", "Disconnected.");
              urlConnection.disconnect();
          }
      }
  </code></pre>
  
  <p>When network access is performed via WIFI, results are consistently fast.</p>
  
  <p>Has anyone encountered similar results? Can something be done to achieve consistent fast network access via GPRS when an incoming call is received?</p>
  
  <p>Thanks,</p>