Reputation: 270
I'm working on an Android application using AndroidAnnotation.
The app make REST calls to my remote API. So I setup AA and my REST client. But I want to write generic code for handling response data.
I got a RestClient class where the @Rest annotation is defined a RestCall class where functions to be call with params and callback function and I guess i need to code an interface called ResponseHandler for eventslistener.
The way I want to use my RestClient is simple, i just want to be able to do so: (like javascript)
@Click
public buttonId(){
//button clicked makes api call
RestCall.callUserItems(user_id, new ResponseHandler(){
@Overide
onSuccess(items){/* CODE TO EXEC ON UITHREAD FOR ITEMS */}
@Overide
onError(error object){/* CODE TO EXEC ON UITHREAD FOR ERRORS */}
});
}
but i don't know how to build the handler interface listening for receive datas event from my RestClient, and i dunno how to pass generic objects types..
I hope I'm clear on my explanations.
Can you help me ? Thanks a lot.
Upvotes: 0
Views: 154
Reputation: 938
You have to do it that way:
try {
RestCall.callUserItems(user_id);
} catch (RestClientException e) {
// handle error for Rest client exceptions
}
Upvotes: 0
Reputation: 2696
I'm sorry, this may not be the answer you are looking for,
but I would recommend using Retrofit to handle the REST calls.
Upvotes: 1