Skip to content

Instantly share code, notes, and snippets.

@raykibul
Created December 22, 2019 08:08
Show Gist options
  • Select an option

  • Save raykibul/8637a5653e1b6afa238c814a640a98db to your computer and use it in GitHub Desktop.

Select an option

Save raykibul/8637a5653e1b6afa238c814a640a98db to your computer and use it in GitHub Desktop.
Volley Library Singleton class .
import android.content.Context;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
public class MySingleton {
private static MySingleton mInstance;
private RequestQueue requestQueue;
private static Context nCtx;
private MySingleton(Context context) {
nCtx=context;
requestQueue=getRequestQueue();
}
public static synchronized MySingleton getmInstance(Context context){
if(mInstance==null)
{
mInstance=new MySingleton(context);
}
return mInstance;
}
public <T> void AddToRequestQueue(Request<T>request){
requestQueue.add(request);
}
public RequestQueue getRequestQueue(){
if(requestQueue==null){
requestQueue=Volley.newRequestQueue(nCtx.getApplicationContext());
}
return requestQueue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment