Search code examples
androidandroid-annotationsnetworkonmainthread

NetworkOnMainThreadException in AndroidAnnotations


I have a class annotated with @Rest and I use its methods in another with an instance of this, annotated with @RestService. When I call some method of the Rest client class, NetworkOnMainThreadException error appears. I thought that AndroidAnnotations managed the threading in these cases.


Solution

  • AndroidAnnotations does not make the implementation to use a background thread. Actually it should not have to, since it is uncertain whether the call is already on a background thread or not, etc. But you can easily put calls to a background thread with the @Background annotation. With the usage of that, you can simply avoid the AsyncTask boilerplate.