Skip to content

Commit 90b69cf

Browse files
committed
Added Canceling by TAG sample, Closing android-async-http#754
1 parent 8b1243c commit 90b69cf

File tree

8 files changed

+57
-3
lines changed

8 files changed

+57
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Updated RequestParams documentation on handling arrays, sets and maps, along with new RequestParamsDebug sample
1313
- Added BlackholeHttpResponseHandler implementation, which discards all response contents and silents all various log messages (see #416)
1414
- Added LogInterface, it's default implementation and interface option to disable/enable logging library-wide and set logging verbosity
15+
- Added option to TAG RequestHandle and cancel all requests matching specified TAG through `AsyncHttpClient.cancelRequestsByTAG(Object TAG)`
1516

1617
## 1.4.7 (released 9. 5. 2015)
1718

sample/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<activity android:name=".Redirect302Sample" />
3636
<activity android:name=".ThreadingTimeoutSample" />
3737
<activity android:name=".CancelAllRequestsSample" />
38+
<activity android:name=".CancelRequestByTagSample" />
3839
<activity android:name=".CancelRequestHandleSample" />
3940
<activity android:name=".SynchronousClientSample" />
4041
<activity android:name=".IntentServiceSample" />
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Android Asynchronous Http Client Sample
3+
Copyright (c) 2014 Marek Sebera <[email protected]>
4+
http://loopj.com
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package com.loopj.android.http.sample;
20+
21+
import android.util.Log;
22+
23+
import com.loopj.android.http.AsyncHttpClient;
24+
import com.loopj.android.http.RequestHandle;
25+
import com.loopj.android.http.ResponseHandlerInterface;
26+
27+
import org.apache.http.Header;
28+
import org.apache.http.HttpEntity;
29+
30+
public class CancelRequestByTagSample extends ThreadingTimeoutSample {
31+
32+
private static final String LOG_TAG = "CancelRequestByTagSample";
33+
private static final Integer REQUEST_TAG = 132435;
34+
35+
@Override
36+
public int getSampleTitle() {
37+
return R.string.title_cancel_tag;
38+
}
39+
40+
@Override
41+
public void onCancelButtonPressed() {
42+
Log.d(LOG_TAG, "Canceling requests by TAG: " + REQUEST_TAG);
43+
getAsyncHttpClient().cancelRequestsByTAG(REQUEST_TAG, false);
44+
}
45+
46+
@Override
47+
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
48+
return client.get(this, URL, headers, null, responseHandler).setTag(REQUEST_TAG);
49+
}
50+
}

sample/src/main/java/com/loopj/android/http/sample/CancelRequestHandleSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
public class CancelRequestHandleSample extends ThreadingTimeoutSample {
2626

27-
private static final String LOG_TAG = "ThreadingTimeoutSample";
27+
private static final String LOG_TAG = "CancelRequestHandleSample";
2828

2929
@Override
3030
public int getSampleTitle() {

sample/src/main/java/com/loopj/android/http/sample/FilesSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
public class FilesSample extends PostSample {
1919

20-
public static final String LOG_TAG = "PostFilesSample";
20+
public static final String LOG_TAG = "FilesSample";
2121

2222
@Override
2323
public int getSampleTitle() {

sample/src/main/java/com/loopj/android/http/sample/Http401AuthSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
*/
5151
public class Http401AuthSample extends GetSample {
5252

53-
private static final String LOG_TAG = "Http401Auth";
53+
private static final String LOG_TAG = "Http401AuthSample";
5454
private static final String HEADER_WWW_AUTHENTICATE = "WWW-Authenticate";
5555
private static final String HEADER_AUTHORIZATION = "Authorization";
5656
private static final String HEADER_REALM_PREFIX = "realm=";

sample/src/main/java/com/loopj/android/http/sample/WaypointsActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class WaypointsActivity extends ListActivity {
4747
new SampleConfig(R.string.title_threading_timeout, ThreadingTimeoutSample.class),
4848
new SampleConfig(R.string.title_cancel_all, CancelAllRequestsSample.class),
4949
new SampleConfig(R.string.title_cancel_handle, CancelRequestHandleSample.class),
50+
new SampleConfig(R.string.title_cancel_tag, CancelRequestByTagSample.class),
5051
new SampleConfig(R.string.title_synchronous, SynchronousClientSample.class),
5152
new SampleConfig(R.string.title_intent_service_sample, IntentServiceSample.class),
5253
new SampleConfig(R.string.title_post_files, FilesSample.class),

sample/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<string name="title_cancel_all">Cancel all requests</string>
3131
<string name="title_sax_example">SAX Example</string>
3232
<string name="title_cancel_handle">Cancel request handle</string>
33+
<string name="title_cancel_tag">Cancel by TAG</string>
3334
<string name="title_synchronous">Synchronous GET request</string>
3435
<string name="title_threading_timeout">Threading timeouts</string>
3536
<string name="title_gzip_sample">GET Gzipped JSON and parse it</string>

0 commit comments

Comments
 (0)