0
# Request Management
1
2
Core request management functionality providing lifecycle-aware image loading with the fluent API pattern. This is the foundation of all Glide operations.
3
4
## Capabilities
5
6
### Glide Entry Point
7
8
Main facade class providing static methods to create lifecycle-aware request managers.
9
10
```java { .api }
11
/**
12
* Main entry point for Glide requests with automatic lifecycle management
13
*/
14
public final class Glide {
15
/** Create request manager tied to application lifecycle */
16
@NonNull public static RequestManager with(@NonNull Context context);
17
18
/** Create request manager tied to activity lifecycle */
19
@NonNull public static RequestManager with(@NonNull Activity activity);
20
21
/** Create request manager tied to fragment lifecycle */
22
@NonNull public static RequestManager with(@NonNull Fragment fragment);
23
24
/** Create request manager tied to FragmentActivity lifecycle */
25
@NonNull public static RequestManager with(@NonNull FragmentActivity activity);
26
27
/** Get Glide singleton instance */
28
@NonNull public static Glide get(@NonNull Context context);
29
30
/** Initialize with custom configuration */
31
public static void init(@NonNull Context context, @NonNull GlideBuilder builder);
32
33
/** Cleanup resources */
34
public static void tearDown();
35
}
36
```
37
38
**Usage Examples:**
39
40
```java
41
// Application context - lives for app lifetime
42
RequestManager appManager = Glide.with(getApplicationContext());
43
44
// Activity context - automatically paused/resumed with activity
45
RequestManager activityManager = Glide.with(this); // from Activity
46
47
// Fragment context - handles fragment lifecycle
48
RequestManager fragmentManager = Glide.with(this); // from Fragment
49
```
50
51
### RequestManager
52
53
Manages requests with lifecycle awareness and provides entry points for creating request builders.
54
55
```java { .api }
56
/**
57
* Manages image requests with lifecycle awareness
58
*/
59
public class RequestManager implements ComponentCallbacks2, LifecycleListener {
60
/** Load image from URL string */
61
@NonNull public RequestBuilder<Drawable> load(@Nullable String string);
62
63
/** Load image from URI */
64
@NonNull public RequestBuilder<Drawable> load(@Nullable Uri uri);
65
66
/** Load image from File */
67
@NonNull public RequestBuilder<Drawable> load(@Nullable File file);
68
69
/** Load image from resource ID */
70
@NonNull public RequestBuilder<Drawable> load(@Nullable @DrawableRes Integer resourceId);
71
72
/** Load image from byte array */
73
@NonNull public RequestBuilder<Drawable> load(@Nullable byte[] model);
74
75
/** Load image from Bitmap */
76
@NonNull public RequestBuilder<Drawable> load(@Nullable Bitmap bitmap);
77
78
/** Load image from Drawable */
79
@NonNull public RequestBuilder<Drawable> load(@Nullable Drawable drawable);
80
81
/** Create request builder for specific type */
82
@NonNull public <ResourceType> RequestBuilder<ResourceType> as(@NonNull Class<ResourceType> resourceClass);
83
84
/** Download only (no display) */
85
@NonNull public RequestBuilder<File> download(@Nullable Object model);
86
87
/** Download image data as bytes */
88
@NonNull public RequestBuilder<File> downloadOnly();
89
90
/** Clear specific target */
91
public void clear(@NonNull View view);
92
public void clear(@Nullable Target<?> target);
93
94
/** Lifecycle management */
95
public void pauseRequests();
96
public void pauseAllRequests();
97
public void resumeRequests();
98
public void pauseRequestsRecursive();
99
public void resumeRequestsRecursive();
100
101
/** Check if paused */
102
public boolean isPaused();
103
104
/** Apply default request options to all requests */
105
@NonNull public RequestManager applyDefaultRequestOptions(@NonNull RequestOptions requestOptions);
106
107
/** Set default transition options */
108
@NonNull public <T> RequestManager setDefaultTransitionOptions(@NonNull Class<T> clazz, @Nullable TransitionOptions<?, T> options);
109
}
110
```
111
112
**Usage Examples:**
113
114
```java
115
RequestManager requestManager = Glide.with(context);
116
117
// Load different types of sources
118
requestManager.load("https://example.com/image.jpg").into(imageView);
119
requestManager.load(R.drawable.placeholder).into(imageView);
120
requestManager.load(new File("/path/to/image.png")).into(imageView);
121
requestManager.load(uriFromContentProvider).into(imageView);
122
123
// Type-specific requests
124
requestManager.as(Bitmap.class).load(imageUrl).into(customBitmapTarget);
125
requestManager.as(GifDrawable.class).load(gifUrl).into(imageView);
126
127
// Download only
128
requestManager.download(imageUrl).into(downloadTarget);
129
130
// Lifecycle management
131
requestManager.pauseRequests(); // Pause all requests
132
requestManager.resumeRequests(); // Resume requests
133
requestManager.clear(imageView); // Clear specific request
134
```
135
136
### RequestBuilder
137
138
Fluent API for configuring image requests with method chaining.
139
140
```java { .api }
141
/**
142
* Fluent request builder for configuring image loading
143
*/
144
public class RequestBuilder<TranscodeType> implements Cloneable, ModelTypes<RequestBuilder<TranscodeType>> {
145
/** Load from various model types (inherited from ModelTypes) */
146
@NonNull public RequestBuilder<TranscodeType> load(@Nullable Object model);
147
@NonNull public RequestBuilder<TranscodeType> load(@Nullable Bitmap bitmap);
148
@NonNull public RequestBuilder<TranscodeType> load(@Nullable Drawable drawable);
149
@NonNull public RequestBuilder<TranscodeType> load(@Nullable String string);
150
@NonNull public RequestBuilder<TranscodeType> load(@Nullable Uri uri);
151
@NonNull public RequestBuilder<TranscodeType> load(@Nullable File file);
152
@NonNull public RequestBuilder<TranscodeType> load(@Nullable @RawRes @DrawableRes Integer resourceId);
153
@NonNull public RequestBuilder<TranscodeType> load(@Nullable byte[] model);
154
155
/** Apply request options */
156
@NonNull public RequestBuilder<TranscodeType> apply(@NonNull RequestOptions requestOptions);
157
158
/** Set thumbnail request */
159
@NonNull public RequestBuilder<TranscodeType> thumbnail(@Nullable RequestBuilder<TranscodeType> thumbnailRequest);
160
@NonNull public RequestBuilder<TranscodeType> thumbnail(float sizeMultiplier);
161
162
/** Set request listener */
163
@NonNull public RequestBuilder<TranscodeType> listener(@Nullable RequestListener<TranscodeType> requestListener);
164
165
/** Add request listener */
166
@NonNull public RequestBuilder<TranscodeType> addListener(@Nullable RequestListener<TranscodeType> requestListener);
167
168
/** Set error request */
169
@NonNull public RequestBuilder<TranscodeType> error(@Nullable RequestBuilder<TranscodeType> errorBuilder);
170
171
/** Clone request builder */
172
@SuppressWarnings("unchecked")
173
@CheckResult
174
@Override
175
public RequestBuilder<TranscodeType> clone();
176
177
/** Load into target */
178
@NonNull public <Y extends Target<TranscodeType>> Y into(@NonNull Y target);
179
@NonNull public ViewTarget<ImageView, TranscodeType> into(@NonNull ImageView view);
180
181
/** Submit for background execution */
182
@NonNull public FutureTarget<TranscodeType> submit(int width, int height);
183
@NonNull public FutureTarget<TranscodeType> submit();
184
185
/** Preload into cache */
186
@NonNull public Target<TranscodeType> preload(int width, int height);
187
@NonNull public Target<TranscodeType> preload();
188
}
189
```
190
191
**Usage Examples:**
192
193
```java
194
RequestBuilder<Drawable> builder = Glide.with(context).load(imageUrl);
195
196
// Method chaining
197
builder
198
.placeholder(R.drawable.loading)
199
.error(R.drawable.error)
200
.centerCrop()
201
.into(imageView);
202
203
// Thumbnail loading
204
Glide.with(context)
205
.load(highResImageUrl)
206
.thumbnail(0.25f) // Load at 25% size first
207
.into(imageView);
208
209
// Error fallback
210
Glide.with(context)
211
.load(primaryImageUrl)
212
.error(Glide.with(context).load(fallbackImageUrl))
213
.into(imageView);
214
215
// Preloading
216
Glide.with(context)
217
.load(imageUrl)
218
.preload(300, 300);
219
220
// Background loading
221
FutureTarget<Drawable> future = Glide.with(context)
222
.load(imageUrl)
223
.submit(500, 500);
224
```
225
226
### Request Lifecycle Management
227
228
Methods for controlling request execution and lifecycle.
229
230
```java { .api }
231
/**
232
* Request interface for lifecycle control
233
*/
234
public interface Request {
235
/** Begin request execution */
236
void begin();
237
238
/** Clear/cancel request */
239
void clear();
240
241
/** Check if request is paused */
242
boolean isPaused();
243
244
/** Pause request execution */
245
void pause();
246
247
/** Check request state */
248
boolean isRunning();
249
boolean isComplete();
250
boolean isCleared();
251
boolean isFailed();
252
253
/** Check if requests are equivalent */
254
boolean isEquivalentTo(@NonNull Request other);
255
}
256
```
257
258
**Usage Examples:**
259
260
```java
261
// Get request from target
262
Target<Drawable> target = Glide.with(context)
263
.load(imageUrl)
264
.into(imageView);
265
266
Request request = target.getRequest();
267
if (request != null) {
268
request.pause(); // Pause specific request
269
request.clear(); // Cancel and clear request
270
}
271
272
// Check request state
273
if (request.isRunning()) {
274
// Request is currently executing
275
}
276
```
277
278
## Types
279
280
```java { .api }
281
// Model types interface
282
public interface ModelTypes<T> {
283
@NonNull T load(@Nullable Object model);
284
@NonNull T load(@Nullable Bitmap bitmap);
285
@NonNull T load(@Nullable Drawable drawable);
286
@NonNull T load(@Nullable String string);
287
@NonNull T load(@Nullable Uri uri);
288
@NonNull T load(@Nullable File file);
289
@NonNull T load(@Nullable @RawRes @DrawableRes Integer resourceId);
290
@NonNull T load(@Nullable byte[] model);
291
}
292
293
// Lifecycle listener interface
294
public interface LifecycleListener {
295
void onStart();
296
void onStop();
297
void onDestroy();
298
}
299
```