Reputation: 319
I have a scenario where I need to call the Webservices from the Android Services. Currently I am starting the Services from the Activity by
Intent mServiceIntent = new Intent(this, AServices.class);
if (!isMyServiceRunning(AServices.class)) {
startService(mServiceIntent);
}
But I am getting an exception as android.os.NetworkOnMainThreadException. As I am following MVVM Architecture so is there any way or alternative that I can call it from AsyncTask and any other stuffs?
Upvotes: 0
Views: 85
Reputation: 157487
Service runs on the UI Thread. If you need a Service extend IntentService
or the newly JobIntentService
and not Service
. Both IntentService
(onHandleIntent
) and JobIntentService
(onHandleWork
) will be executed on thread != from the UI/Main thread
Upvotes: 0