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?
Service runs on the UI Thread. If you need a Service extend
IntentServiceor the newlyJobIntentServiceand notService. BothIntentService(onHandleIntent) andJobIntentService(onHandleWork) will be executed on thread != from the UI/Main thread