com.android.volley.RequestQueue.start()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(83)

本文整理了Java中com.android.volley.RequestQueue.start方法的一些代码示例,展示了RequestQueue.start的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RequestQueue.start方法的具体详情如下:
包路径:com.android.volley.RequestQueue
类名称:RequestQueue
方法名:start

RequestQueue.start介绍

[英]Starts the dispatchers in this queue.
[中]启动此队列中的调度程序。

代码示例

代码示例来源:origin: stackoverflow.com

public static RequestQueue newRequestQueueForTest(final Context context, final OkHttpClient okHttpClient) {
  final File cacheDir = new File(context.getCacheDir(), "volley");

  final Network network = new BasicNetwork(new OkHttpStack(okHttpClient));

  final ResponseDelivery responseDelivery = new ExecutorDelivery(Executors.newSingleThreadExecutor());

  final RequestQueue queue =
      new RequestQueue(
          new DiskBasedCache(cacheDir),
          network,
          4,
          responseDelivery);

  queue.start();

  return queue;
}

代码示例来源:origin: chentao0707/SimplifyReader

/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link android.content.Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
  File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);
  String userAgent = "volley/0";
  try {
    String packageName = context.getPackageName();
    PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
    userAgent = packageName + "/" + info.versionCode;
  } catch (NameNotFoundException e) {
  }
  if (stack == null) {
    if (Build.VERSION.SDK_INT >= 9) {
      stack = new HurlStack();
    } else {
      // Prior to Gingerbread, HttpUrlConnection was unreliable.
      // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
      stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
    }
  }
  Network network = new BasicNetwork(stack);
  RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
  queue.start();
  return queue;
}

代码示例来源:origin: jiangqqlmj/FastDev4Android

/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
  File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);
  String userAgent = "volley/0";
  try {
    String packageName = context.getPackageName();
    PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
    userAgent = packageName + "/" + info.versionCode;
  } catch (NameNotFoundException e) {
  }
  if (stack == null) {
    if (Build.VERSION.SDK_INT >= 9) {
      stack = new HurlStack();
    } else {
      // Prior to Gingerbread, HttpUrlConnection was unreliable.
      // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
      stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
    }
  }
  Network network = new BasicNetwork(stack);
  RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
  queue.start();
  return queue;
}

代码示例来源:origin: mcxiaoke/android-volley

queue.start();

代码示例来源:origin: mcxiaoke/android-volley

/**
 * Verify RequestFinishedListeners are informed when request errors
 *
 * Needs to be an integration test because relies on Request -> dispatcher -> RequestQueue interaction
 */
@Test public void add_requestFinishedListenerError() throws Exception {
  RequestFinishedListener listener = mock(RequestFinishedListener.class);
  Request request = new MockRequest();
  RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 1, mDelivery);
  when(mMockNetwork.performRequest(request)).thenThrow(new VolleyError());
  queue.addRequestFinishedListener(listener);
  queue.start();
  queue.add(request);
  verify(listener, timeout(100)).onRequestFinished(request);
  queue.stop();
}

代码示例来源:origin: stackoverflow.com

RequestQueue serialRequestQueue = prepareSerialRequestQueue(context);
serialRequestQueue.start();

代码示例来源:origin: mcxiaoke/android-volley

/**
 * Verify RequestFinishedListeners are informed when requests are successfully delivered
 *
 * Needs to be an integration test because relies on Request -> dispatcher -> RequestQueue interaction
 */
@Test public void add_requestFinishedListenerSuccess() throws Exception {
  NetworkResponse response = mock(NetworkResponse.class);
  Request request = new MockRequest();
  RequestFinishedListener listener = mock(RequestFinishedListener.class);
  RequestFinishedListener listener2 = mock(RequestFinishedListener.class);
  RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 1, mDelivery);
  queue.addRequestFinishedListener(listener);
  queue.addRequestFinishedListener(listener2);
  queue.start();
  queue.add(request);
  verify(listener, timeout(100)).onRequestFinished(request);
  verify(listener2, timeout(100)).onRequestFinished(request);
  queue.stop();
}

代码示例来源:origin: jiangqqlmj/FastDev4Android

/**
 * Verify RequestFinishedListeners are informed when request errors
 *
 * Needs to be an integration test because relies on Request -> dispatcher -> RequestQueue interaction
 */
@Test public void add_requestFinishedListenerError() throws Exception {
  RequestFinishedListener listener = mock(RequestFinishedListener.class);
  Request request = new MockRequest();
  RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 1, mDelivery);
  when(mMockNetwork.performRequest(request)).thenThrow(new VolleyError());
  queue.addRequestFinishedListener(listener);
  queue.start();
  queue.add(request);
  verify(listener, timeout(100)).onRequestFinished(request);
  queue.stop();
}

代码示例来源:origin: mcxiaoke/android-volley

queue.add(req1);
queue.add(req2);
queue.start();

代码示例来源:origin: jiangqqlmj/FastDev4Android

/**
 * Verify RequestFinishedListeners are informed when requests are successfully delivered
 *
 * Needs to be an integration test because relies on Request -> dispatcher -> RequestQueue interaction
 */
@Test public void add_requestFinishedListenerSuccess() throws Exception {
  NetworkResponse response = mock(NetworkResponse.class);
  Request request = new MockRequest();
  RequestFinishedListener listener = mock(RequestFinishedListener.class);
  RequestFinishedListener listener2 = mock(RequestFinishedListener.class);
  RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 1, mDelivery);
  queue.addRequestFinishedListener(listener);
  queue.addRequestFinishedListener(listener2);
  queue.start();
  queue.add(request);
  verify(listener, timeout(100)).onRequestFinished(request);
  verify(listener2, timeout(100)).onRequestFinished(request);
  queue.stop();
}

代码示例来源:origin: mcxiaoke/android-volley

/**
 * Verify RequestFinishedListeners are informed when requests are canceled
 *
 * Needs to be an integration test because relies on Request -> dispatcher -> RequestQueue interaction
 */
@Test public void add_requestFinishedListenerCanceled() throws Exception {
  RequestFinishedListener listener = mock(RequestFinishedListener.class);
  Request request = new MockRequest();
  Answer<NetworkResponse> delayAnswer = new Answer<NetworkResponse>() {
    @Override
    public NetworkResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
      Thread.sleep(200);
      return mock(NetworkResponse.class);
    }
  };
  RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 1, mDelivery);
  when(mMockNetwork.performRequest(request)).thenAnswer(delayAnswer);
  queue.addRequestFinishedListener(listener);
  queue.start();
  queue.add(request);
  request.cancel();
  verify(listener, timeout(100)).onRequestFinished(request);
  queue.stop();
}

代码示例来源:origin: jiangqqlmj/FastDev4Android

queue.add(req1);
queue.add(req2);
queue.start();

代码示例来源:origin: jiangqqlmj/FastDev4Android

/**
 * Verify RequestFinishedListeners are informed when requests are canceled
 *
 * Needs to be an integration test because relies on Request -> dispatcher -> RequestQueue interaction
 */
@Test public void add_requestFinishedListenerCanceled() throws Exception {
  RequestFinishedListener listener = mock(RequestFinishedListener.class);
  Request request = new MockRequest();
  Answer<NetworkResponse> delayAnswer = new Answer<NetworkResponse>() {
    @Override
    public NetworkResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
      Thread.sleep(200);
      return mock(NetworkResponse.class);
    }
  };
  RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 1, mDelivery);
  when(mMockNetwork.performRequest(request)).thenAnswer(delayAnswer);
  queue.addRequestFinishedListener(listener);
  queue.start();
  queue.add(request);
  request.cancel();
  verify(listener, timeout(100)).onRequestFinished(request);
  queue.stop();
}

代码示例来源:origin: mcxiaoke/android-volley

queue.add(lowerPriorityReq);
queue.add(higherPriorityReq);
queue.start();

代码示例来源:origin: jiangqqlmj/FastDev4Android

queue.add(lowerPriorityReq);
queue.add(higherPriorityReq);
queue.start();

代码示例来源:origin: stackoverflow.com

File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);
DiskBasedCache cache = new DiskBasedCache(cacheDir);
RequestQueue queue = new RequestQueue(cache, network);
queue.start();

// clear all volley caches.
queue.add(new ClearCacheRequest(cache, null));

代码示例来源:origin: stackoverflow.com

RequestQueue mRequestQueue;

// Instantiate the cache
Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap

// Set up the network to use HttpURLConnection as the HTTP client.
Network network = new BasicNetwork(new HurlStack());

// Instantiate the RequestQueue with the cache and network.
mRequestQueue = new RequestQueue(cache, network);

// Start the queue
mRequestQueue.start();

代码示例来源:origin: stackoverflow.com

//Specific test queue that uses a singleThreadExecutor instead of the mainLooper for testing purposes.
public RequestQueue newVolleyRequestQueueForTest(final Context context) {
  File cacheDir = new File(context.getCacheDir(), "cache/volley");
  Network network = new BasicNetwork(new HurlStack());
  ResponseDelivery responseDelivery = new ExecutorDelivery(Executors.newSingleThreadExecutor());
  RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network, 4, responseDelivery);
  queue.start();
  return queue;
}

代码示例来源:origin: SkyTreasure/Airbnb-Android-Google-Map-View

public RequestQueue getRequestQueue() {
  if (mRequestQueue == null) {
    Cache cache = new DiskBasedCache(mCtx.getCacheDir(), 10 * 1024 * 1024);
    Network network = new BasicNetwork(new HurlStack());
    mRequestQueue = new RequestQueue(cache, network);
    // Don't forget to start the volley request queue
    mRequestQueue.start();
  }
  return mRequestQueue;
}

代码示例来源:origin: googlecast/CastVideos-android

private RequestQueue getRequestQueue() {
  if (requestQueue == null) {
    Cache cache = new DiskBasedCache(context.getCacheDir(), 10 * 1024 * 1024);
    Network network = new BasicNetwork(new HurlStack());
    requestQueue = new RequestQueue(cache, network);
    requestQueue.start();
  }
  return requestQueue;
}

相关文章