Created
December 22, 2019 08:08
-
-
Save raykibul/8637a5653e1b6afa238c814a640a98db to your computer and use it in GitHub Desktop.
Volley Library Singleton class .
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
| 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