【发布时间】:2013-12-09 17:05:59
【问题描述】:
Volley ImageLoader 强制要求应该从主 UI 线程发起请求:
public ImageContainer get(String requestUrl, ImageListener imageListener,
int maxWidth, int maxHeight) {
// only fulfill requests that were initiated from the main thread.
throwIfNotOnMainThread();
我认为这是为了保证响应回调发生在主 UI 线程上,大概是因为假设调用者希望在回调中更新 UI。
但是,我想在处理 GCM 通知时使用 Volley,它只需要发送 PendingIntent,而不是直接更新 UI。我想知道在这种特殊情况下删除throwIfNotOnMainThread() 是否安全。我怀疑这是否安全,但我想知道是否有人可以给出一个充分的理由?
(仅供参考,看起来RequestQueue 已同步访问mCurrentRequests,因此 Volley 内部的请求队列似乎存在内部锁定。)
【问题讨论】: