こんにちは私は以下に指定されているようにHTTPメソッドPOSTを処理するAndroidのサービスを持っています。今、私はインテントを呼び出す必要があります
replaceResourceSegment()
方法。タスクを完了するのに約90秒かかるハンドラーがあります。その時間内に、制御はハンドラーブロックを終了します。しかし、POSTのハンドラー内でプログラムを続行したい。つまり、インテント(ハンドラー付き)が実行を完了し、HTTP Postの応答の送信を遅らせる必要があるまで、POSTハンドラー内でサービスを一時停止する必要があります。誰かがこの実装を行う方法を教えてもらえますか?
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");
}
応答を送り返すためのコード:
HttpResponse postResponse = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
postResponse.setEntity(new StringEntity("Got it"));
conn.sendResponseHeader(postResponse);
conn.sendResponseEntity(postResponse);