glide icon indicating copy to clipboard operation
glide copied to clipboard

ANR during RequestManager Initialization

Open prithvibhola opened this issue 1 year ago • 3 comments

We are encountering an ANR which appears to occur when Glide.with() is used to load images, with the stack trace pointing to delays during RequestManager initialization and decoding.

Here’s a relevant portion of the stack trace:

   at com.bumptech.glide.request.RequestOptions.decodeTypeOf(RequestOptions.java:213)
   at com.bumptech.glide.RequestManager.<clinit>(RequestManager.java:59)
   at com.bumptech.glide.GeneratedRequestManagerFactory.build(GeneratedRequestManagerFactory.java:18)
   at com.bumptech.glide.manager.LifecycleRequestManagerRetriever.getOrCreate(LifecycleRequestManagerRetriever.java:43)
   at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:158)
   at com.bumptech.glide.Glide.with(Glide.java:540)
   ... 

The ANR happens during image loading, likely due to some operations such as decoding or request initialization being performed on the main thread.

Glide Version: 4.15.1

Integration libraries: No

Device/Android Version: Based on Firebase Crashlytics data, the ANR occurs on multiple devices, with a significant number of occurrences on Oppo devices running Android 11.

Glide load line / GlideModule (if any) / list Adapter code (if any): We have a helper function that is called from a fragment to load a profile image.

fun loadImageWithScopedContext(
        context: Context,
        imageView: ImageView,
        photoUrl: String?,
        @DrawableRes placeholder: Int
) {
    if (isEmpty(photoUrl)) return

    Glide.with(context)
            .load(photoUrl)
            .dontAnimate()
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .placeholder(placeholder)
            .into(imageView)
}

Layout XML:

<ImageView
            android:id="@+id/profilePicture"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_marginStart="16dp"
            android:layout_marginTop="16dp"
            android:clickable="true"
            android:elevation="8dp"
            android:focusable="true"
            android:src="@drawable/home_page_avatar_placeholder"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

prithvibhola avatar Oct 23 '24 07:10 prithvibhola