So my question is: what is the best way to make asynchronous calls. I am currently using an async task that calls a method that returns a string in a background method and parses the string through another call to the static method used for parsing, which returns a POJO containing all the data that I send to postExecute, where I present results on ui based on the result. Is this a good practice or is there a better method?
IMO, if AsyncTask suits your needs, you should use it - it was created specifically to help you avoid thread management issues for tasks .......
I was thinking about the possibility of introducing interfaces for providing data, for example, the onSuccess listener and onFail Listener. so any suggestions on this?
Not quite sure what you mean here, but of course you want to handle failure gracefully. One way to do this is based only on the return value of your AsyncTask , but if you have many different possible failure scenarios, splitting them into a listener / callback pattern is definitely a valid option. I personally will do not two, but one listener, for example:
interface MyHttpCallListener { public void onSuccess(MyResult returnVal); public void onFailure(MyError error); }
It seems cleaner to me.
thanks.
No problems.
source share