Skip to content

Instantly share code, notes, and snippets.

@myamamic
Created November 25, 2015 09:39
Show Gist options
  • Save myamamic/94ce8799dd33d47bdb0a to your computer and use it in GitHub Desktop.
Save myamamic/94ce8799dd33d47bdb0a to your computer and use it in GitHub Desktop.
[android] Volley用クラス
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