Later, I found out that my application was freezing and slowing down not because there were too many threads generated by it. But this was due to the fact that I used the Service, not the IntentService. And my IO network happened in the main thread in the Service. This means that a blocking IO will suppress the main thread, and the phone / application will tend to die and display ANR.
Subsequently, I changed my project to run network I / O operations on spawned threads in my services that brought life back to the application. Everything was smoother as expected.
Thus, whenever your services lead to ANR, make sure that if you do not use IntentService (they run tasks in separate threads), then you perform blocking operations on new threads.
Hope this helps someone.
source share