I'm getting a NetworkOnMainThreadException
in my Service
class, which by nature doesn't make sense, because Services are background processes as far as I understand.
In the Service method, I'm making a call to a static helper method to download data. I'm using the DefaultHttpClient as well.
What's going on here?
http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html
Service callbacks all run on the main thread, aka the UI thread. If you wish to do background work, either start a Thread, or use IntentService's onHandleIntent(Intent i).
i just resolve this problem by using this :
RefreshDBAsync is making request to a server at every 5 minutes
onStartCommand()
runs on the UI thread in aService
. Try using IntentService, or alternatively use any other threading method in theService
(Handler
/Runnable
,AsyncTask
).