本文整理匯總了Java中com.android.volley.RequestQueue.cancelAll方法的典型用法代碼示例。如果您正苦於以下問題:Java RequestQueue.cancelAll方法的具體用法?Java RequestQueue.cancelAll怎麽用?Java RequestQueue.cancelAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.android.volley.RequestQueue
的用法示例。
在下文中一共展示了RequestQueue.cancelAll方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: RegisterStep1Request
import com.android.volley.RequestQueue; //導入方法依賴的package包/類
/**
* 注冊第一步——檢查手機號是否已注冊
*
* @param button Loading Button
* @param activity Register Activity
* @param phoneNumber 手機號碼
*/
public static void RegisterStep1Request(final LoadingButton button,
final RegisterActivity activity, final String phoneNumber) {
//請求地址
String url = HttpRequestUtils.SERVER_ROOT + "iReading/*";
String tag = "RegisterByPhoneNumberStep1";
//取得請求隊列
RequestQueue requestQueue = MyApplication.getRequestQueue();
//防止重複請求,所以先取消tag標識的請求隊列
requestQueue.cancelAll(tag);
//創建StringRequest,定義字符串請求的請求方式為POST(省略第一個參數會默認為GET方式)
final StringRequest request = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = (JSONObject) new JSONObject(response).get("params");
String result = jsonObject.getString("IsNew");
if (result.equals("true")) {
button.loadingSuccessful();
} else {
button.loadingFailed();
activity.showToast("該手機號已經被注冊,驗證手機號後可直接登錄");
}
} catch (JSONException e) {
activity.showToast("網絡請求發生錯誤,稍後請重試");
button.loadingFailed();
Log.e("TAG", e.getMessage(), e);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
activity.showToast("網絡請求發生錯誤,稍後請重試");
button.loadingFailed();
Log.e("TAG", error.getMessage(), error);
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("RequestType", "Register");
params.put("RegisterType", "RegisterByPhoneNumber");
params.put("RegisterStep", "1");
params.put("PhoneNumber", phoneNumber);
return params;
}
};
//設置Tag標簽
request.setTag(tag);
//將請求添加到隊列中
requestQueue.add(request);
}
示例2: RegisterStep3Request
import com.android.volley.RequestQueue; //導入方法依賴的package包/類
/**
* 注冊第三步——設置密碼
*
* @param button Loading Button
* @param activity Register Activity
* @param phoneNumber 手機號碼
* @param password 密碼
*/
public static void RegisterStep3Request(final LoadingButton button, final RegisterActivity activity,
final String phoneNumber, final String password) {
//請求地址
String url = HttpRequestUtils.SERVER_ROOT + "iReading/*";
String tag = "RegisterByPhoneNumberStep3";
//取得請求隊列
RequestQueue requestQueue = MyApplication.getRequestQueue();
//防止重複請求,所以先取消tag標識的請求隊列
requestQueue.cancelAll(tag);
//創建StringRequest,定義字符串請求的請求方式為POST(省略第一個參數會默認為GET方式)
final StringRequest request = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = (JSONObject) new JSONObject(response).get("params");
String result = jsonObject.getString("RegisterResult");
if (result.equals("true")) {
button.loadingSuccessful();
} else {
button.loadingFailed();
activity.showToast("服務器繁忙,請稍後重試");
}
} catch (JSONException e) {
activity.showToast("網絡請求發生錯誤,稍後請重試");
button.loadingFailed();
Log.e("TAG", e.getMessage(), e);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
activity.showToast("網絡請求發生錯誤,稍後請重試");
button.loadingFailed();
Log.e("TAG", error.getMessage(), error);
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("RequestType", "Register");
params.put("RegisterType", "RegisterByPhoneNumber");
params.put("RegisterStep", "3");
params.put("PhoneNumber", phoneNumber);
params.put("Password", password);
return params;
}
};
//設置Tag標簽
request.setTag(tag);
//將請求添加到隊列中
requestQueue.add(request);
}
示例3: LoginByPasswordRequest
import com.android.volley.RequestQueue; //導入方法依賴的package包/類
/**
* 通過賬號密碼登錄
*
* @param typeID 登錄類型ID
* @param button Loading Button
* @param activity Login Activity
* @param accountNumber 賬號
* @param password 密碼
*/
public static void LoginByPasswordRequest(final int typeID, final LoadingButton button,
final LoginActivity activity, final String accountNumber,
final String password) {
//請求地址
String url = HttpRequestUtils.SERVER_ROOT + "iReading/*";
String tag = LOGIN_TYPE[typeID];
//取得請求隊列
RequestQueue requestQueue = MyApplication.getRequestQueue();
//防止重複請求,所以先取消tag標識的請求隊列
requestQueue.cancelAll(tag);
//創建StringRequest,定義字符串請求的請求方式為POST(省略第一個參數會默認為GET方式)
final StringRequest request = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = (JSONObject) new JSONObject(response).get("params");
String result = jsonObject.getString("Result");
if (result.equals("success")) {
button.loadingSuccessful();
} else {
activity.showToast("賬號或密碼錯誤,請重新輸入");
button.loadingFailed();
}
} catch (JSONException e) {
activity.showToast("網絡請求發生錯誤,稍後請重試");
button.loadingFailed();
Log.e("TAG", e.getMessage(), e);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
activity.showToast("網絡請求發生錯誤,稍後請重試");
button.loadingFailed();
Log.e("TAG", error.getMessage(), error);
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("RequestType", "Login");
params.put("LoginType", LOGIN_TYPE[typeID]);
params.put("AccountNumber", accountNumber);
params.put("Password", password);
return params;
}
};
//設置Tag標簽
request.setTag(tag);
//將請求添加到隊列中
requestQueue.add(request);
}
示例4: SearchAllBooksRequest
import com.android.volley.RequestQueue; //導入方法依賴的package包/類
/**
* 查詢所有書籍
*/
public static void SearchAllBooksRequest(final SimpleAdapter adapter, final RecyclerView view) {
//請求地址
String url = HttpRequestUtils.SERVER_ROOT + "iReading/*";
String tag = "SearchAllBooks";
//取得請求隊列
RequestQueue requestQueue = MyApplication.getRequestQueue();
//防止重複請求,所以先取消tag標識的請求隊列
requestQueue.cancelAll(tag);
//創建StringRequest,定義字符串請求的請求方式為POST(省略第一個參數會默認為GET方式)
final StringRequest request = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = (JSONObject) new JSONObject(response).get("params");
MyApplication.books = jsonObject.getJSONArray("Books");
BookListFragment.insertItems(adapter, view);
} catch (JSONException e) {
Log.e("TAG", e.getMessage(), e);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("TAG", error.getMessage(), error);
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("RequestType", "SearchAllBooks");
return params;
}
};
//設置Tag標簽
request.setTag(tag);
//將請求添加到隊列中
requestQueue.add(request);
}