我有 2 个请求需要执行
onStart(...){
callFirstWS();
callSecondWS();
}
每个函数都使用具有这种格式的 Singleton 类
SingletonClass.getInstance(<activity>).addToRequestQueue(<request>);
单身阶级
public final class InternetSingleton {
private static InternetSingleton singleton;
private RequestQueue requestQueue;
private static Context context;
private InternetSingleton(Context context) {
InternetSingleton.context = context;
requestQueue = getRequestQueue();
}
public static synchronized InternetSingleton getInstance(Context context) {
if (singleton == null) {
singleton = new InternetSingleton(context);
}
return singleton;
}
public RequestQueue getRequestQueue() {
if (requestQueue == null) {
requestQueue = Volley.newRequestQueue(context.getApplicationContext());
}
return requestQueue;
}
public void addToRequestQueue(Request request) {
getRequestQueue().add(request);
}
}
当我运行我的应用程序时,第一个 WS 被调用,第二个没有任何想法?