I have several subclasses of Activity in my project, each of which calls a SOAP-based web service, processes and displays the results. SOAP serialization, call processing, and parsing of the result into various POJOs are encapsulated in the MyWebService class. This class makes an actual web service call through AsyncTask.
In order to pass the results to a subclass of the calling activity, I decided that all these actions should implement the WebServiceResultProcessor interface defining one function (processWebServiceResults) acting as a callback for AsyncTask called from onPostExecute.
I also want to display the ProgressDialog during a web service call. And here is my question. In order to display the ProgressDialog (either from MyWebService or AsyncTask), I need to pass a link to the caller's activity context. And in order to execute the callback function from AsyncTask, I also need to pass the same object reference, but this time as a WebServiceResultProcessor. It seems to me like a code smell, passing the same object twice, but I see no way around it. Instead of interacting, I could create a new base class by extending the Activity class and applying inheritance from the extension class, but this would mean that I excluded ListActivity and the like from this MyWebService class.
Is there a better way to do this?
source
share