12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Volleyの起動・停止・キャンセル

Last updated at Posted at 2013-10-03

Volleyを使う際は、こんな風にしておくと便利かも?
アプリが終了する際などに、stop()とcancel()を呼べばOK

	// シングルトンのキュー
	private static RequestQueue mQueue;

	// addするrequestを生成
	start(context);
	mQueue.add(request);

	// キュー処理をスタート
	public static final void start(Context context){
		if(mQueue == null) mQueue = Volley.newRequestQueue(context);
		mQueue.start();
	}
	// キュー処理をストップ
	public static final void stop(){
		if(mQueue != null) mQueue.stop();
	}

	// リクエストをキャンセル
	public static final void cancel(){
		if(mQueue != null){
			mQueue.cancelAll(new RequestFilter() {
				@Override
				public boolean apply(Request<?> request) { return true; }
			});
		}
	}
```
12
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?