Note that there are some explanatory texts on larger screens.

plurals
  1. POHttp Response inside a service in Android
    primarykey
    data
    text
    <p>Hi I have a service in Android that handles the HTTP method POST as specified below. Now, I need to call an Intent in </p> <blockquote> <p>replaceResourceSegment() </p> </blockquote> <p>method. It has a handler that takes nearly 90 seconds to complete the task. Within that time, control exits the handler block. But I want my program to continue within handler for POST. In short, I want my service to pause for sometime inside the POST handler, till my Intent (with handler) completes its execution and I need to delay sending the response of HTTP Post. Can some one guide me how to do this implementation?</p> <pre><code> if(method.equals("POST")) { conn.receiveRequestEntity((HttpEntityEnclosingRequest)request); HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity(); String content_type = ""+entity.getContentType(); JSONReceived = EntityUtils.toString(entity); if(content_type.contains("json")) { Log.d(TAG,"Content received is: "+JSONReceived); bufferedWriter = new BufferedWriter(new FileWriter(new File(getFilesDir()+File.separator+constants.UPDATED_SCRIPT_FILE))); bufferedWriter.write(JSONReceived); bufferedWriter.close(); try { parseJSON(JSONReceived); replaceResourceSegment(); //Call to an intent with startActivityForResult() continueExecution(); //Continue the execution from here } catch (IOException e) { e.printStackTrace(); Log.d(TAG,"IOException line 157"); } </code></pre> <p>Code for sending response back:</p> <pre><code> HttpResponse postResponse = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"); postResponse.setEntity(new StringEntity("Got it")); conn.sendResponseHeader(postResponse); conn.sendResponseEntity(postResponse); </code></pre>
    singulars
    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.
    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