You cannot start a load for a destroyed activity in relativelayout image using glide

后端 未结 10 894
悲&欢浪女
悲&欢浪女 2020-12-02 19:33

I am using relativelayout to set an image.Why I hadn\'t using imageview means, inside relativelayout image, I am setting icons.

I dont know what is the issue exactly

相关标签:
10条回答
  • 2020-12-02 20:21

    Setup Glide with a parameter which has the correct lifecycle. For example: use Glide.with(this) instead of Glide.with(getContext()) in a custom view.

    0 讨论(0)
  • 2020-12-02 20:26

    Try this before load your image with Glide, in my case mirefer is a StorageReference, miimagen is a ImageView. I solved this problem, with this. I hope it could help you.

    if (!this.isFinishing ()) {
                    // Load the image using Glide
                    Glide.with(YourActivity.this)
                            .using(new FirebaseImageLoader())
                            .load(mirefer)
                            .into(miimagen);
                }
    
    0 讨论(0)
  • 2020-12-02 20:30

    Please do not use Glide.with(getApplicationContext()) unless you really need to, for reasons discussed here: Glide image loading with application context

    The correct answer is outlined here: https://github.com/bumptech/glide/issues/1484#issuecomment-365625087

    In Kotlin, that can be written as an extension function:

    fun Context.isValidGlideContext() = this !is Activity || (!this.isDestroyed && !this.isFinishing)
    
    0 讨论(0)
  • 2020-12-02 20:32

    the other way is to check if the activity is destroyed or not, then load into UI element.

    if (!newActivty.isDestroyed()){
       ...
    }
    
    0 讨论(0)
提交回复
热议问题