アプリがサーバーに接続し、アプリを終了するときにサーバーからログアウトする必要があります。
私の問題は、応答の遅延です。私のアプリはすぐに終了しません。Handler を離れる前に、サーバーからの応答を待つ必要があります。
応答は重要ではありません。get を送信すると、ログアウトされると確信しています。
それで、応答を待たずに(ただし、「取得プロセス」を停止せずに)ログアウトして(http getで)アプリを閉じることは可能ですか?
ブラウザを使用してコンピューターで行うのとまったく同じです。ログアウトボタンをクリックしてから、サーバーからのウェルカムページを待たずにブラウザを閉じます...
短いソケット タイムアウトを追加してみましたが、サーバーはログアウトしません。
これが私の方法です:
private void Disconnect() {
new Thread() {
@Override
public void run() {
String errorMessage = null;
Message msg = authHandler.obtainMessage();
try {
HttpGet httpGet = new HttpGet(LogoutURL);
HttpResponse httpResponse = httpclient.execute(httpGet);
if (httpResponse.getStatusLine().getStatusCode() != 200) {
msg.what = AuthERR;
authHandler.sendMessage(msg);
return;
}
msg.what = AuthEND;
msg.obj = choix;
authHandler.sendMessage(msg);
} catch (ClientProtocolException e) {
errorMessage = e.toString();
} catch (IllegalArgumentException e) {
errorMessage = e.toString();
} catch (IOException e) {
errorMessage = e.toString();
} catch (Exception e) {
errorMessage = e.toString();
} finally {
if (errorMessage != null) {
Log.e("Logout", errorMessage);
msg.what = AuthUnknownHostException;
msg.obj = errorMessage;
authHandler.sendMessage(msg);
}
}
}
}.start();
}