Created
November 25, 2015 09:39
-
-
Save myamamic/94ce8799dd33d47bdb0a to your computer and use it in GitHub Desktop.
[android] Volley用クラス
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 RequestManager { | |
// Singleton | |
private static RequestManager mInstance = new RequestManager(); | |
private RequestManager() { | |
} | |
private boolean mIsInitialzed = false; | |
private RequestQueue mReqQueue = null; | |
public static RequestManager getInstance() { | |
return mInstance; | |
} | |
public void init(Context context) { | |
if (!mIsInitialzed) { | |
mReqQueue = Volley.newRequestQueue(context); | |
mIsInitialzed = true; | |
} | |
} | |
public void destroy() { | |
mIsInitialzed = false; | |
if (mReqQueue != null) { | |
mReqQueue.stop(); | |
mReqQueue = null; | |
} | |
} | |
public Request<?> addRequest(Request<?> request) { | |
if (mReqQueue != null) { | |
return mReqQueue.add(request); | |
} | |
return null; | |
} | |
public void cancelRequest(Request<?> request) { | |
request.cancel(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment