我有一个监听器,可以将截击响应发送到发出请求的活动:
public interface MyListener{
void interpretResponseListener(String response);
void interpretErrorListener(VolleyError error);
}
用于拨打电话的方法:
public static void myVolleyRequest(int request code,MyListener myListener){
...
...
}
活动代码:
private MyListener myListener = new MyListener(){
@Override
void interpretResponseListener(String response){
//database changes
}
@Override
void interpretErrorListener(VolleyError error){
//database changes
}
};
myVolleyRequest(100,myListener);
我在响应中对数据库进行了更改。 Leakcanary给了我以下错误:
GC ROOT com.android.volley.NetworkDispatcher.<Java Local>
* references com.test.restful.Request.mListener
* references com.test.restfulRestful$44.val$myListener (anonymous class implements com.android.volley.Response$Listener)
* references com.test.Activity$8.this$0 (anonymous class implements com.test.restful.Restful$MyListener)
* leaks com.test.Activity instance