]> iEval git - fonbot.git/commitdiff
Stop long polling on error
authorMarius Gavrilescu <marius@ieval.ro>
Wed, 31 Jul 2013 05:20:52 +0000 (08:20 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Wed, 31 Jul 2013 05:20:52 +0000 (08:20 +0300)
src/ro/ieval/fonbot/FonBotMainActivity.java
src/ro/ieval/fonbot/FonBotMainService.java
src/ro/ieval/fonbot/PollResultCallback.java

index b879be0c203c1a2c90548d43f66e4cec730ce609..2c2a49d2b11b0087f39fbf819ff99e811bd9a9e1 100644 (file)
@@ -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));
+                                       }
                                }
                        });
                }
index 38e0a29d0cbb8b4fd8a850ba28474b3e5ea54ccb..13dc1316449a081c7e656eea6679e606955d44e1 100644 (file)
@@ -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");
                }
index 370ec11d9b8582fcc9bca6696f846caf11d035c4..46e3eda83e39cc4ed15455ea0fc64f05f6c4f787 100644 (file)
@@ -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);
        }
 
 }
This page took 0.032066 seconds and 4 git commands to generate.