Created
September 19, 2019 00:04
-
-
Save musoftware/5ffd14d9b5801b68bfc677bdbd020f70 to your computer and use it in GitHub Desktop.
MySingleton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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