I get an exception of networking in the main thread. Should I try to do it from a IntentService and can I even start an IntentService from a Service? Is it a good practice?
Asked
Active
Viewed 57 times
-1
-
add your logcat and your code – Oussema Aroua Jul 24 '17 at 10:03
1 Answers
1
You should not do network related heavy operation from main thread. You can use AsyncTask/Thread to call api.
You can also use networking library like volley, retrofit etc.
Refer this link : https://developer.android.com/guide/components/processes-and-threads.html#WorkerThreads

Pratik Popat
- 2,891
- 20
- 31
-
Hello, thanks for the answers. I wanted to use asyncTask then I've read somewhere that it could give some troubles when you put some networking task in an asyncTask and it was better to use an IntentService. What do you think about that? Is that true? – magiccus Jul 24 '17 at 12:31
-
-
I've not faced any. I've read from a experienced user that it was not safe to use asyncTask for networking. I don't remember really what he said but I think he said it could give troubles when the activity is recreated or the screen rotated. He recommended to use only IntentService for networking operations. – magiccus Jul 29 '17 at 14:54