From: Marius Gavrilescu Date: Wed, 31 Jul 2013 05:20:52 +0000 (+0300) Subject: Stop long polling on error X-Git-Tag: 0.000_001~12 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;ds=sidebyside;h=c7b1fdf5aa45b0459095e780d0929f8ddd80d8fb;p=fonbot.git Stop long polling on error --- 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); } }