Skip to content

Instantly share code, notes, and snippets.

@musoftware
Created September 19, 2019 00:04
Show Gist options
  • Save musoftware/5ffd14d9b5801b68bfc677bdbd020f70 to your computer and use it in GitHub Desktop.
Save musoftware/5ffd14d9b5801b68bfc677bdbd020f70 to your computer and use it in GitHub Desktop.
MySingleton
package me.amcapp.amc.Tasks;
import android.content.Context;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
/**
* Created by CHEA THAILY on 11/8/2017.
*/
public class MySingleton {
private static MySingleton mInstance;
private RequestQueue requestQueue;
private static Context mContext;
private MySingleton(Context context) {
mContext = context;
requestQueue = getRequestQueue();
}
public RequestQueue getRequestQueue() {
if (requestQueue == null) {
requestQueue = Volley.newRequestQueue(mContext.getApplicationContext());
}
return requestQueue;
}
public static synchronized MySingleton getInstance(Context context) {
if (mInstance == null) {
mInstance = new MySingleton(context);
}
return mInstance;
}
public <T> void addToRequestque(Request<T> request) {
getRequestQueue().add(request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment