@@ -25,33 +25,31 @@ public class IntentServiceSample extends SampleParentActivity {
25
25
public static final String ACTION_FINISH = "SYNC_FINISH" ;
26
26
public static final String [] ALLOWED_ACTIONS = {ACTION_START ,
27
27
ACTION_RETRY , ACTION_CANCEL , ACTION_SUCCESS , ACTION_FAILURE , ACTION_FINISH };
28
- private BroadcastReceiver broadcastReceiver = new BroadcastReceiver () {
28
+ private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver () {
29
29
@ Override
30
30
public void onReceive (Context context , Intent intent ) {
31
- switch (intent .getAction ()) {
32
- case ACTION_START :
33
- clearOutputs ();
34
- addView (getColoredView (LIGHTBLUE , "Request started" ));
35
- break ;
36
- case ACTION_FINISH :
37
- addView (getColoredView (LIGHTBLUE , "Request finished" ));
38
- break ;
39
- case ACTION_CANCEL :
40
- addView (getColoredView (LIGHTBLUE , "Request cancelled" ));
41
- break ;
42
- case ACTION_RETRY :
43
- addView (getColoredView (LIGHTBLUE , "Request retried" ));
44
- break ;
45
- case ACTION_FAILURE :
46
- debugThrowable (LOG_TAG , (Throwable ) intent .getSerializableExtra (ExampleIntentService .INTENT_THROWABLE ));
47
- case ACTION_SUCCESS :
31
+ String action = intent .getAction ();
32
+
33
+ // switch() doesn't support strings in older JDK.
34
+ if (ACTION_START .equals (action )) {
35
+ clearOutputs ();
36
+ addView (getColoredView (LIGHTBLUE , "Request started" ));
37
+ } else if (ACTION_FINISH .equals (action )) {
38
+ addView (getColoredView (LIGHTBLUE , "Request finished" ));
39
+ } else if (ACTION_CANCEL .equals (action )) {
40
+ addView (getColoredView (LIGHTBLUE , "Request cancelled" ));
41
+ } else if (ACTION_RETRY .equals (action )) {
42
+ addView (getColoredView (LIGHTBLUE , "Request retried" ));
43
+ } else if (ACTION_FAILURE .equals (action ) || ACTION_SUCCESS .equals (action )) {
44
+ debugThrowable (LOG_TAG , (Throwable ) intent .getSerializableExtra (ExampleIntentService .INTENT_THROWABLE ));
45
+ if (ACTION_SUCCESS .equals (action )) {
48
46
debugStatusCode (LOG_TAG , intent .getIntExtra (ExampleIntentService .INTENT_STATUS_CODE , 0 ));
49
47
debugHeaders (LOG_TAG , IntentUtil .deserializeHeaders (intent .getStringArrayExtra (ExampleIntentService .INTENT_HEADERS )));
50
48
byte [] returnedBytes = intent .getByteArrayExtra (ExampleIntentService .INTENT_DATA );
51
49
if (returnedBytes != null ) {
52
50
debugResponse (LOG_TAG , new String (returnedBytes ));
53
51
}
54
- break ;
52
+ }
55
53
}
56
54
}
57
55
};
0 commit comments