I am using volley library for making web-services call. I made a general class for making all web services call and making service call from there and made anonymous listene
Basically the anonymous approach is terrible in Android
or in any ClientSideSystem
where you don't have massive memory. What is happening is, you have passed Context
as parameter in method and anonymous
holds a reference of it. The real mess comes now in the scene when the thread inside which makes network call
could not finish it's job and before that the calling activity for some reason either destroys or recycles in that case GC
is not able to collect the activity as wokerThread
might still be holding reference onto it. Please go through this for detail description.
The solution could be either static inner classes or independent classes, in both cases use WeakReference
to hold resources and do a null check before using them.
Advantage of WeakReference
is it will allow GC
to collect the object if no-one else if holding reference onto it.