From c7b1fdf5aa45b0459095e780d0929f8ddd80d8fb Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Wed, 31 Jul 2013 08:20:52 +0300 Subject: [PATCH] Stop long polling on error --- src/ro/ieval/fonbot/FonBotMainActivity.java | 4 +++- src/ro/ieval/fonbot/FonBotMainService.java | 1 + src/ro/ieval/fonbot/PollResultCallback.java | 6 +++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ro/ieval/fonbot/FonBotMainActivity.java b/src/ro/ieval/fonbot/FonBotMainActivity.java index b879be0..2c2a49d 100644 --- a/src/ro/ieval/fonbot/FonBotMainActivity.java +++ b/src/ro/ieval/fonbot/FonBotMainActivity.java @@ -173,8 +173,10 @@ public final class FonBotMainActivity extends ListActivity { resultTextView.setText(message); if(error) resultTextView.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.cross, 0, 0); - else + else { resultTextView.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.tick, 0, 0); + startService(new Intent(FonBotMainActivity.this, FonBotMainService.class)); + } } }); } diff --git a/src/ro/ieval/fonbot/FonBotMainService.java b/src/ro/ieval/fonbot/FonBotMainService.java index 38e0a29..13dc131 100644 --- a/src/ro/ieval/fonbot/FonBotMainService.java +++ b/src/ro/ieval/fonbot/FonBotMainService.java @@ -80,6 +80,7 @@ public final class FonBotMainService extends Service { runnable.run(); } catch (final Exception ex){ ex.printStackTrace(); + break; } Log.d("LongPollRunnable", "Long polling stopped"); } diff --git a/src/ro/ieval/fonbot/PollResultCallback.java b/src/ro/ieval/fonbot/PollResultCallback.java index 370ec11..46e3eda 100644 --- a/src/ro/ieval/fonbot/PollResultCallback.java +++ b/src/ro/ieval/fonbot/PollResultCallback.java @@ -55,8 +55,11 @@ final class PollResultCallback implements ResultCallback { @Override public void onResult(final int responseCode, final String responseMessage, final @Nullable InputStream inputStream) { - if(responseCode!=200 || inputStream==null) + if(responseCode != 200 || inputStream==null){ + if(responseCode != 204) + throw new RuntimeException("Bad HTTP response code: "+responseCode); return; + } final Handler handler=new Handler(Looper.getMainLooper()); @@ -99,6 +102,7 @@ final class PollResultCallback implements ResultCallback { @Override public void onError(final String error) { Log.e("PollResultCallback", "onError: "+error); + throw new RuntimeException(error); } } -- 2.39.2