@@ -106,8 +106,7 @@ Tracking a download's progress and status is very easy with Fetch. Simply add a
106
106
status or progress changes.
107
107
108
108
```java
109
-
110
- fetch.addListener (new FetchListener () {
109
+ final FetchListener fetchListener = new FetchListener () {
111
110
@Override
112
111
public void onQueued (@NotNull Download download ) {
113
112
if (request. getId() == download. getId()) {
@@ -127,11 +126,11 @@ fetch.addListener(new FetchListener() {
127
126
128
127
@Override
129
128
public void onProgress (@NotNull Download download , long etaInMilliSeconds , long downloadedBytesPerSecond ) {
130
- if (request. getId() == download. getId()) {
131
- updateDownload(download, etaInMilliSeconds);
132
- }
133
- final int progress = download. getProgress();
134
- Log . d(" Fetch" , " Progress Completed :" + progress);
129
+ if (request. getId() == download. getId()) {
130
+ updateDownload(download, etaInMilliSeconds);
131
+ }
132
+ final int progress = download. getProgress();
133
+ Log . d(" Fetch" , " Progress Completed :" + progress);
135
134
}
136
135
137
136
@Override
@@ -158,7 +157,12 @@ fetch.addListener(new FetchListener() {
158
157
public void onDeleted (@NotNull Download download ) {
159
158
160
159
}
161
- });
160
+ };
161
+
162
+ fetch.addListener (fetchListener );
163
+
164
+ // Note: Remove listener when done.
165
+ fetch.removeListener (fetchListener );
162
166
```
163
167
164
168
Fetch supports pausing and resuming downloads using the request' s id.
0 commit comments