I have created an android module(module project) that helps to access HTTP calls (Http Module wrap volley). I want to make Volley.newRequestQueue(mContext); into a place that initialize once rather than creating every time (To avoid memory overflows). A better place would be the Application class but from the module, I do not want to access the application. Is there any place I can initialize volley requestQue once and then use it. Was there a component like application in the module?
Asked
Active
Viewed 307 times
0
-
Have a look https://stackoverflow.com/questions/33535435/how-to-create-a-proper-volley-listener-for-cross-class-volley-method-calling – IntelliJ Amiya May 02 '18 at 08:56
1 Answers
0
I did create a singleton class in my module to get the request
public class RequestQueSingleton {
private static RequestQueSingleton sSoleInstance;
private static RequestQueue reQuestQue;
private RequestQueSingleton(){} //private constructor.
public static RequestQueSingleton getInstance(Context context){
if (sSoleInstance == null){ //if there is no instance available... create new one
sSoleInstance = new RequestQueSingleton();
reQuestQue = Volley.newRequestQueue(context);
}
return sSoleInstance;
}
public synchronized RequestQueue getInstance() {
Log.d("Request Que Obj",reQuestQue.hashCode()+"");
return reQuestQue;
}
}

Eoin
- 4,050
- 2
- 33
- 43

Chinthaka Devinda
- 997
- 5
- 16
- 36