In my Android application I want to call some web-app methods. I use hessian for this (hessdroid library for Android).
That's how it works: In my Android app I have interfaces for all of the the server methods e.g. getUserById(), getMessageById(), getSomethingElse() etc.
With Hessian I can call these methods through http.
So I need to initalize Hessian Proxy for that:
HessianProxyFactory proxyFactory = new HessianProxyFactory();
UserAccountService api = (UserAccountService) proxyFactory.create(UserAccountService.class, "http://localhost:8080/server/UserAccountService", getClassLoader());
After that I am able to run server methods like that:
UserAccount user = api.getUserById(999);
The problem is that api calls like "api.someMethod();" require running from separeted thread. In any other case I have NetworkOnMainThread exception.
My question is about how to make these calls in right way? Should I create AsyncTask for every server method call? Or it is possible to make that more generic? I really dont think that creating AsyncTask for every method is a right way. It makes code dirty.
Any ideas? I really appreciate any solution you can provide.