使用了request.start(),所以才导致的问题。
public static void RequstGet_JSONObject() {
request.cancelAll(tag);
jsonObjectRequest.setTag(tag);
request.add(jsonObjectRequest);
request.start();
}
因为在volley在初始化RequestQueue时,已经调用了start方法。
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, );
userAgent = packageName + "/" + info.versionCode;
} catch (NameNotFoundException e) {
}
if (stack == null) {
if (Build.VERSION.SDK_INT >= ) {
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;
}
解决方法:
去掉request.start(),即可。
public static void RequstGet_JSONObject() {
request.cancelAll(tag);
jsonObjectRequest.setTag(tag);
request.add(jsonObjectRequest);
}