Save image once Glide has loaded it
<p>I load images using <code>Glide</code> like such:</p>

<pre><code>Glide.with(getContext()).load(apdInfo.url)
         .thumbnail(0.5f)
         .crossFade()
         .diskCacheStrategy(DiskCacheStrategy.ALL)
         .into(apd_image);
</code></pre>

<p>And wish to save the Bitmap loaded like such:</p>

<pre><code>private void saveImage() {
    final ImageView apd_image = (ImageView) view.findViewById(R.id.apd_image);
    final InternalFileHandler IFH = new InternalFileHandler(getContext());

    apd_image.setDrawingCacheEnabled(true);
    apd_image.buildDrawingCache(true);
    Bitmap bitmap = apd_image.getDrawingCache();

    // Simply saves the bitmap in the filesystem
    IFH.savePicture("APD", bitmap, getContext());
    apd_image.destroyDrawingCache();
}
</code></pre>

<p>The issue is that if I call <code>saveImage</code> before <code>Glide</code> has loaded my picture, it won't work.</p>

<p>How may I wait or <code>Glide</code> to load it? Please note that using <code>Glide</code>'s listeners did not work.</p>

<p><strong>EDIT</strong>:</p>

<p>I now use the following listeners:</p>

<pre><code> .listener(new RequestListener&lt;String, GlideDrawable&gt;() {
                @Override
                public boolean onException(Exception e, String model, Target&lt;GlideDrawable&gt; target, boolean isFirstResource) {
                    //handle the exception.
                    return true;
                }

                @Override
                public boolean onResourceReady(GlideDrawable resource, String model, Target&lt;GlideDrawable&gt; target, boolean isFromMemoryCache, boolean isFirstResource) {
                    // onResourceReady is called twice for some reason, this is my work around for now
                    if (first) {
                        GlideBitmapDrawable glideBitmapDrawable = (GlideBitmapDrawable) resource;
                        // Convert to Bitmap
                        Bitmap bm = glideBitmapDrawable.getBitmap();
                        saveImage(bm);
                        first = false;
                    } else {
                        first = true;
                    }
                    return true;
                }
            })
</code></pre>