When making a REST WebService call in the service class of my Android application, NetworkOnMainThreadException .
I understand why this exception occurs in Activity: getting something over the network synchronously is a very bad practice, but I am surprised to see the same error in the service class. So my question is:
- In this particular case, I should use StrictMode.setThreadPolicy() to resolve this call. (And for those who read this because they encountered this error in action, do not use StrictMode to hide this error, use AsyncTask)
- or should I use AsyncTask? And in this case, what is the problem? Isn't the service disconnected from one action?
Teovald
source share