我在制作Google排球请求时使用过setTags。如何在内联onResponse或响应监听器中使用getTag或其他方法?
public boolean VolleyRequestWrapper(final int which, String url, final String volleyTag) {
JsonObjectRequest jsonObjReq = null;
jsonObjReq = new JsonObjectRequest(
Method.GET,
url,
null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
??????.getTag(); // <----- THIS IS WHERE I WANT TO get the Tag.
}
}, new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
VolleyLog.d(volleyTag, "Error: " + error.getMessage());
volleyException = true;
}
});
// Adding request to request queue
jsonObjReq.setTag(volleyTag); // I can set the tag
requestQueue.add(jsonObjReq);
return !volleyException;
}
我看过,但没有找到一个使用getTag的好例子,我还没有找到关于凌空的文档。任何帮助,将不胜感激。
度过美好的一天。
答案 0 :(得分:0)
我试图探索它,似乎没有任何方法可以实现区分多个标记请求的机制,它似乎是Volly的限制,使用IntentService而不是包含HTTP的Volly的替代解决方案代码并在从您的网络rrequest获得的响应对象中提供标记
答案 1 :(得分:0)
您分配给请求的标记存储在变量mTag中,该变量在请求的整个生命周期中保持不变。
对于我的应用程序,我使用稍微修改过的Volley类将其发回 以及回应。
/** Callback interface for delivering parsed responses. */
public interface Listener<T> {
/** Called when a response is received. */
public void onResponse(Object tag, T response);
}
有关详细信息,请参阅我的回答https://stackoverflow.com/a/37129734/4419474以获取类似问题。