@@ -61,8 +61,29 @@ public void onSuccess(JSONObject response) {}
61
61
*/
62
62
public void onSuccess (JSONArray response ) {}
63
63
64
+ public void onFailure (Throwable e , JSONObject errorResponse ) {}
65
+ public void onFailure (Throwable e , JSONArray errorResponse ) {}
66
+
67
+
68
+ //
69
+ // Pre-processing of messages (executes in background threadpool thread)
70
+ //
71
+
72
+ @ Override
73
+ protected void sendSuccessMessage (String responseBody ) {
74
+ try {
75
+ Object jsonResponse = parseResponse (responseBody );
76
+ sendMessage (obtainMessage (SUCCESS_JSON_MESSAGE , jsonResponse ));
77
+ } catch (JSONException e ) {
78
+ sendFailureMessage (e , responseBody );
79
+ }
80
+ }
81
+
82
+
83
+ //
84
+ // Pre-processing of messages (in original calling thread, typically the UI thread)
85
+ //
64
86
65
- // Utility methods
66
87
@ Override
67
88
protected void handleMessage (Message msg ) {
68
89
switch (msg .what ){
@@ -84,26 +105,10 @@ protected void handleSuccessJsonMessage(Object jsonResponse) {
84
105
}
85
106
}
86
107
87
- @ Override
88
- protected void sendSuccessMessage (String responseBody ) {
89
- try {
90
- Object jsonResponse = parseResponse (responseBody );
91
- sendMessage (obtainMessage (SUCCESS_JSON_MESSAGE , jsonResponse ));
92
- } catch (JSONException e ) {
93
- sendFailureMessage (e , responseBody );
94
- }
95
- }
96
-
97
108
protected Object parseResponse (String responseBody ) throws JSONException {
98
109
return new JSONTokener (responseBody ).nextValue ();
99
110
}
100
111
101
- /**
102
- * Handle cases where a failure is returned as JSON
103
- */
104
- public void onFailure (Throwable e , JSONObject errorResponse ) {}
105
- public void onFailure (Throwable e , JSONArray errorResponse ) {}
106
-
107
112
@ Override
108
113
protected void handleFailureMessage (Throwable e , String responseBody ) {
109
114
if (responseBody != null ) try {
0 commit comments