Volley在通过SyncAdapter运行时响应哪个线程?

时间:2016-04-05 15:08:22

标签: multithreading android-volley

我有一个非常简单的问题。无法在网上找到答案。

我的应用程序有一个syncadapter,它使用Volley在onPerformSync方法中执行请求。

我的问题是,当触发volley的Response.Lisener时,onResponse方法是在主线程上还是在与onPerformSync方法相同的线程上运行?

谢谢!

1 个答案:

答案 0 :(得分:0)

在主线程上..因为ExecutorDelivery:

 mResponsePoster = new Executor() {
        @Override
        public void execute(Runnable command) {
            handler.post(command);
        }
    };

其中:handler(在请求队列中)创建:

 public RequestQueue(Cache cache, Network network, int threadPoolSize) {
    this(cache, network, threadPoolSize,
            new ExecutorDelivery(new Handler(Looper.getMainLooper())));
}

您可以通过传递自己的ResponseDelivery实现来覆盖此行为