with

open fun with(context: Context): RequestManager

Begin a load with Glide by passing in a context.

Any requests started using a context will only have the application level options applied and will not be started or stopped based on lifecycle events. In general, loads should be started at the level the result will be used in. If the resource will be used in a view in a child fragment, the load should be started with with} using that child fragment. Similarly, if the resource will be used in a view in the parent fragment, the load should be started with with using the parent fragment. In the same vein, if the resource will be used in a view in an activity, the load should be started with with}.

This method is appropriate for resources that will be used outside of the normal fragment or activity lifecycle (For example in services, or for notification thumbnails).

Return

A RequestManager for the top level application that can be used to start a load.

See also

with(android.app.Fragment)
with(androidx.fragment.app.Fragment)

Parameters

context

Any context, will not be retained.


open fun with(activity: Activity): RequestManager

Begin a load with Glide that will be tied to the given android.app.Activity's lifecycle and that uses the given Activity's default options.

Return

A RequestManager for the given activity that can be used to start a load.

Deprecated

TODO(judds): Figure out the end state and list it here.

Parameters

activity

The activity to use.


open fun with(activity: FragmentActivity): RequestManager

Begin a load with Glide that will tied to the give 's lifecycle and that uses the given 's default options.

Return

A RequestManager for the given FragmentActivity that can be used to start a load.

Parameters

activity

The activity to use.


open fun with(fragment: Fragment): RequestManager

Begin a load with Glide that will be tied to the given androidx.fragment.app.Fragment's lifecycle and that uses the given androidx.fragment.app.Fragment's default options.

Return

A RequestManager for the given Fragment that can be used to start a load.

Parameters

fragment

The fragment to use.


open fun with(fragment: Fragment): RequestManager

Begin a load with Glide that will be tied to the given android.app.Fragment's lifecycle and that uses the given android.app.Fragment's default options.

Return

A RequestManager for the given Fragment that can be used to start a load.

Deprecated

Prefer support Fragments and with instead, will be deprecated. See https://github.com/android/android-ktx/pull/161#issuecomment-363270555.

Parameters

fragment

The fragment to use.


open fun with(view: View): RequestManager

Begin a load with Glide that will be tied to the lifecycle of the Fragment, , or Activity that contains the View.

A Fragment or android.app.Fragment is assumed to contain a View if the View is a child of the View returned by the getView} method.

This method will not work if the View is not attached. Prefer the Activity and Fragment variants unless you're loading in a View subclass.

This method may be inefficient aways and is definitely inefficient for large hierarchies. Consider memoizing the result after the View is attached or again, prefer the Activity and Fragment variants whenever possible.

When used in Applications that use the non-support android.app.Fragment classes, calling this method will produce noisy logs from android.app.FragmentManager. Consider avoiding entirely or using the Fragments from the support library instead.

If the support FragmentActivity class is used, this method will only attempt to discover support Fragments. Any non-support android.app.Fragments attached to the FragmentActivity will be ignored.

Return

A RequestManager that can be used to start a load.

Parameters

view

The view to search for a containing Fragment or Activity from.