aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/android/volley/toolbox/Volley.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/android/volley/toolbox/Volley.java')
-rw-r--r--src/main/java/com/android/volley/toolbox/Volley.java18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/main/java/com/android/volley/toolbox/Volley.java b/src/main/java/com/android/volley/toolbox/Volley.java
index 1982802..bc65c9c 100644
--- a/src/main/java/com/android/volley/toolbox/Volley.java
+++ b/src/main/java/com/android/volley/toolbox/Volley.java
@@ -86,8 +86,22 @@ public class Volley {
}
private static RequestQueue newRequestQueue(Context context, Network network) {
- File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);
- RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
+ final Context appContext = context.getApplicationContext();
+ // Use a lazy supplier for the cache directory so that newRequestQueue() can be called on
+ // main thread without causing strict mode violation.
+ DiskBasedCache.FileSupplier cacheSupplier =
+ new DiskBasedCache.FileSupplier() {
+ private File cacheDir = null;
+
+ @Override
+ public File get() {
+ if (cacheDir == null) {
+ cacheDir = new File(appContext.getCacheDir(), DEFAULT_CACHE_DIR);
+ }
+ return cacheDir;
+ }
+ };
+ RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheSupplier), network);
queue.start();
return queue;
}