安卓凌空响应未在某些活动中被调用



我正在发出 Volley GET 请求,它将工作,直到我进入特定活动,然后它停止调用Response.Listener中的onResponse。这是我的凌空请求方法:

    public static void stringReqGet(String url, final VolleyCallback callback){
    StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            System.out.println("In VolleyRequest onResponse(): " + response);
            callback.onSuccess(response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d("Error" ,error.getMessage());
        }
    });
    System.out.println("Adding request to queue: " + stringRequest.toString());
    Utilities.getInstance().addToRequestQueue(stringRequest);
    }

以下是我在相关活动中发出请求的方式:

CourseUtil.loadCourse(courseID, new VolleyCallback() {
        @Override
        public void onSuccess(String response) {
            System.out.println("JSON Success");
            courseJSON = response;
        }
});

CourseUtil班上:

public static void loadCourse(int courseID, VolleyCallback callback){
    VolleyRequest.stringReqGet(Const.URL_COURSE + courseID,callback);
}

我没有收到凌空错误,只是似乎没有回应。这是我的(截断的(日志:

I/System.out: Adding request to queue: [ ] http://server/courses/267267267 0xebb503b0 NORMAL null
I/System.out: In VolleyRequest onResponse(): *Correct Response Object*
.
.
.
I/System.out: 267267267  <-- Same course ID used in first request
I/System.out: Adding request to queue: [ ] http://server/courses/267267267 0xebb503b0 NORMAL null
*onResponse never called*

第一次发出此请求时,您可以看到调用了 onResponse() 方法,并且它返回了正确的对象。此"正确"请求的签名与上述请求完全相同。下次发出确切的请求时,永远不会调用onResponse,并且我没有收到任何错误。

在这里查看了其他帖子,但他们的解决方案都没有解决我遇到的问题,并且没有错误使人很难知道发生了什么。

任何帮助将不胜感激。

放:

System.out.println("JSON Success");
courseJSON = response;

到回调之外的单独方法中,它现在可以工作了。不知道为什么...