<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="06-09 00:13:11.607 11876-11920/com.myapp.app E/art: Throwing OutOfMemoryError &quot;Failed to allocate a 11197452 byte allocation with 16776720 free bytes and 79MB until OOM&quot;
06-09 00:13:11.617 11876-11920/com.myapp.app E/PriorityExecutor: Request threw uncaught throwable
                                                                       java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Failed to allocate a 11197452 byte allocation with 16776720 free bytes and 79MB until OOM
                                                                           at java.util.concurrent.FutureTask.report(FutureTask.java:93)
                                                                           at java.util.concurrent.FutureTask.get(FutureTask.java:163)
                                                                           at com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor.afterExecute(FifoPriorityThreadPoolExecutor.java:96)
                                                                           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1120)
                                                                           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                                           at java.lang.Thread.run(Thread.java:818)
                                                                           at com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor$DefaultThreadFactory$1.run(FifoPriorityThreadPoolExecutor.java:118)
                                                                        Caused by: java.lang.OutOfMemoryError: Failed to allocate a 11197452 byte allocation with 16776720 free bytes and 79MB until OOM
                                                                           at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
                                                                           at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
                                                                           at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
                                                                           at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:728)
                                                                           at com.bumptech.glide.load.resource.bitmap.Downsampler.decodeStream(Downsampler.java:329)
                                                                           at com.bumptech.glide.load.resource.bitmap.Downsampler.downsampleWithSize(Downsampler.java:220)
                                                                           at com.bumptech.glide.load.resource.bitmap.Downsampler.decode(Downsampler.java:153)
                                                                           at com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder.decode(StreamBitmapDecoder.java:50)
                                                                           at com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder.decode(StreamBitmapDecoder.java:19)
                                                                           at com.bumptech.glide.load.resource.bitmap.ImageVideoBitmapDecoder.decode(ImageVideoBitmapDecoder.java:39)
                                                                           at com.bumptech.glide.load.resource.bitmap.ImageVideoBitmapDecoder.decode(ImageVideoBitmapDecoder.java:20)
                                                                           at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decodeBitmapWrapper(GifBitmapWrapperResourceDecoder.java:121)
                                                                           at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decodeStream(GifBitmapWrapperResourceDecoder.java:94)
                                                                           at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decode(GifBitmapWrapperResourceDecoder.java:71)
                                                                           at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decode(GifBitmapWrapperResourceDecoder.java:61)
                                                                           at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decode(GifBitmapWrapperResourceDecoder.java:22)
                                                                           at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperStreamResourceDecoder.decode(GifBitmapWrapperStreamResourceDecoder.java:24)
                                                                           at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperStreamResourceDecoder.decode(GifBitmapWrapperStreamResourceDecoder.java:14)
                                                                           at com.bumptech.glide.load.resource.file.FileToStreamDecoder.decode(FileToStreamDecoder.java:39)
                                                                           at com.bumptech.glide.load.resource.file.FileToStreamDecoder.decode(FileToStreamDecoder.java:17)
                                                                           at com.bumptech.glide.load.engine.DecodeJob.loadFromCache(DecodeJob.java:222)
                                                                           at com.bumptech.glide.load.engine.DecodeJob.decodeResultFromCache(DecodeJob.java:85)
                                                                           at com.bumptech.glide.load.engine.EngineRunnable.decodeFromCache(EngineRunnable.java:108)
                                                                           at com.bumptech.glide.load.engine.EngineRunnable.decode(EngineRunnable.java:99)
                                                                           at com.bumptech.glide.load.engine.EngineRunnable.run(EngineRunnable.java:58)
                                                                           at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
                                                                           at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                                           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
                                                                           at java.lang.Thread.run(Thread.java:818) 
                                                                           at com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor$DefaultThreadFactory$1.run(FifoPriorityThreadPoolExecutor.java:118) 
"><pre class="notranslate"><code class="notranslate">06-09 00:13:11.607 11876-11920/com.myapp.app E/art: Throwing OutOfMemoryError "Failed to allocate a 11197452 byte allocation with 16776720 free bytes and 79MB until OOM"
06-09 00:13:11.617 11876-11920/com.myapp.app E/PriorityExecutor: Request threw uncaught throwable
                                                                       java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Failed to allocate a 11197452 byte allocation with 16776720 free bytes and 79MB until OOM
                                                                           at java.util.concurrent.FutureTask.report(FutureTask.java:93)
                                                                           at java.util.concurrent.FutureTask.get(FutureTask.java:163)
                                                                           at com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor.afterExecute(FifoPriorityThreadPoolExecutor.java:96)
                                                                           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1120)
                                                                           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                                           at java.lang.Thread.run(Thread.java:818)
                                                                           at com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor$DefaultThreadFactory$1.run(FifoPriorityThreadPoolExecutor.java:118)
                                                                        Caused by: java.lang.OutOfMemoryError: Failed to allocate a 11197452 byte allocation with 16776720 free bytes and 79MB until OOM
                                                                           at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
                                                                           at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
                                                                           at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
                                                                           at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:728)
                                                                           at com.bumptech.glide.load.resource.bitmap.Downsampler.decodeStream(Downsampler.java:329)
                                                                           at com.bumptech.glide.load.resource.bitmap.Downsampler.downsampleWithSize(Downsampler.java:220)
                                                                           at com.bumptech.glide.load.resource.bitmap.Downsampler.decode(Downsampler.java:153)
                                                                           at com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder.decode(StreamBitmapDecoder.java:50)
                                                                           at com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder.decode(StreamBitmapDecoder.java:19)
                                                                           at com.bumptech.glide.load.resource.bitmap.ImageVideoBitmapDecoder.decode(ImageVideoBitmapDecoder.java:39)
                                                                           at com.bumptech.glide.load.resource.bitmap.ImageVideoBitmapDecoder.decode(ImageVideoBitmapDecoder.java:20)
                                                                           at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decodeBitmapWrapper(GifBitmapWrapperResourceDecoder.java:121)
                                                                           at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decodeStream(GifBitmapWrapperResourceDecoder.java:94)
                                                                           at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decode(GifBitmapWrapperResourceDecoder.java:71)
                                                                           at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decode(GifBitmapWrapperResourceDecoder.java:61)
                                                                           at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decode(GifBitmapWrapperResourceDecoder.java:22)
                                                                           at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperStreamResourceDecoder.decode(GifBitmapWrapperStreamResourceDecoder.java:24)
                                                                           at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperStreamResourceDecoder.decode(GifBitmapWrapperStreamResourceDecoder.java:14)
                                                                           at com.bumptech.glide.load.resource.file.FileToStreamDecoder.decode(FileToStreamDecoder.java:39)
                                                                           at com.bumptech.glide.load.resource.file.FileToStreamDecoder.decode(FileToStreamDecoder.java:17)
                                                                           at com.bumptech.glide.load.engine.DecodeJob.loadFromCache(DecodeJob.java:222)
                                                                           at com.bumptech.glide.load.engine.DecodeJob.decodeResultFromCache(DecodeJob.java:85)
                                                                           at com.bumptech.glide.load.engine.EngineRunnable.decodeFromCache(EngineRunnable.java:108)
                                                                           at com.bumptech.glide.load.engine.EngineRunnable.decode(EngineRunnable.java:99)
                                                                           at com.bumptech.glide.load.engine.EngineRunnable.run(EngineRunnable.java:58)
                                                                           at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
                                                                           at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                                           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
                                                                           at java.lang.Thread.run(Thread.java:818) 
                                                                           at com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor$DefaultThreadFactory$1.run(FifoPriorityThreadPoolExecutor.java:118) 

</code></pre></div>
<p dir="auto"><strong>## Phone : Note 3 At&amp;T<br>
OS : Android 5.0</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ext {
    supportLibraryVersion = '25.2.0'
    playServicesVersion = '10.2.0'
    retrofit = &quot;2.1.0&quot;
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    /**
     * Support
     * */
    compile &quot;com.android.support:appcompat-v7:$supportLibraryVersion&quot;
    compile &quot;com.android.support:support-v4:$supportLibraryVersion&quot;
    compile &quot;com.android.support:design:$supportLibraryVersion&quot;
    compile &quot;com.android.support:percent:$supportLibraryVersion&quot;

    /**
     * Squareup
     * */
    compile &quot;com.squareup.retrofit2:retrofit:$retrofit&quot;
    compile &quot;com.squareup.retrofit2:converter-gson:$retrofit&quot;
    /**
     *  Google
     * */
    compile &quot;com.google.android.gms:play-services-analytics:$playServicesVersion&quot;
    compile &quot;com.google.firebase:firebase-core:$playServicesVersion&quot;
    compile &quot;com.google.android.gms:play-services-gcm:$playServicesVersion&quot;
    compile &quot;com.google.android.gms:play-services-maps:$playServicesVersion&quot;
    compile 'com.google.guava:guava:22.0-rc1-android'

    compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'com.kyleduo.switchbutton:library:1.4.4'
    compile 'com.github.franmontiel:PersistentCookieJar:v1.0.1'
    compile 'com.github.arimorty:floatingsearchview:2.0.3'
    compile 'org.androidannotations:androidannotations-api:4.1.0'
    compile 'com.wang.avi:library:2.1.3'
    compile 'com.thefinestartist:finestwebview:1.2.7'
    compile 'com.github.pwittchen:reactivenetwork-rx2:0.9.1'
    compile 'me.relex:circleindicator:1.2.2@aar'
    apt 'org.androidannotations:androidannotations:4.1.0'
}"><pre class="notranslate"><code class="notranslate">ext {
    supportLibraryVersion = '25.2.0'
    playServicesVersion = '10.2.0'
    retrofit = "2.1.0"
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    /**
     * Support
     * */
    compile "com.android.support:appcompat-v7:$supportLibraryVersion"
    compile "com.android.support:support-v4:$supportLibraryVersion"
    compile "com.android.support:design:$supportLibraryVersion"
    compile "com.android.support:percent:$supportLibraryVersion"

    /**
     * Squareup
     * */
    compile "com.squareup.retrofit2:retrofit:$retrofit"
    compile "com.squareup.retrofit2:converter-gson:$retrofit"
    /**
     *  Google
     * */
    compile "com.google.android.gms:play-services-analytics:$playServicesVersion"
    compile "com.google.firebase:firebase-core:$playServicesVersion"
    compile "com.google.android.gms:play-services-gcm:$playServicesVersion"
    compile "com.google.android.gms:play-services-maps:$playServicesVersion"
    compile 'com.google.guava:guava:22.0-rc1-android'

    compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'com.kyleduo.switchbutton:library:1.4.4'
    compile 'com.github.franmontiel:PersistentCookieJar:v1.0.1'
    compile 'com.github.arimorty:floatingsearchview:2.0.3'
    compile 'org.androidannotations:androidannotations-api:4.1.0'
    compile 'com.wang.avi:library:2.1.3'
    compile 'com.thefinestartist:finestwebview:1.2.7'
    compile 'com.github.pwittchen:reactivenetwork-rx2:0.9.1'
    compile 'me.relex:circleindicator:1.2.2@aar'
    apt 'org.androidannotations:androidannotations:4.1.0'
}
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="public class ImageHelper {

    static final String TAG = ImageHelper.class.getSimpleName();

    private static void config(String url, ImageView imageView, int width, int height, RequestListener&lt;String, Bitmap&gt; target) {
        if (!TextUtils.isEmpty(url)) {
            try {
                url = UrlHelper.encodeImage(url, width, height);
                if (target == null) {
                    Glide
                            .with(imageView.getContext())
                            .load(url)
                            .asBitmap()
                            .dontAnimate()
                            .placeholder(R.drawable.ic_img_default)
                            .into(imageView);
                } else {
                    Glide
                            .with(imageView.getContext())
                            .load(url)
                            .asBitmap()
                            .dontAnimate()
                            .placeholder(R.drawable.ic_img_default)
                            .listener(target).into(imageView);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            Log.d(TAG, url);
        }
    }

    public static void displayUrl(String url, ImageView imageView, int width, int height) {
        config(url, imageView, width, height, null);
    }

    public static void displayResource(int urlLocal, ImageView imageView) {
        if (imageView != null) {
            displayResource(urlLocal, imageView, ScreenHelper.getWidthPortrait(), ScreenHelper.getWidthPortrait(), null);
        }
    }

    public static void displayResource(int urlLocal, ImageView imageView, int height, int width) {
        if (imageView != null) {
            displayResource(urlLocal, imageView, height, width, null);
        }
    }

    public static void displayResource(int urlLocal, ImageView imageView, RequestListener&lt;Integer, GlideDrawable&gt; listener) {
        if (imageView != null) {
            displayResource(urlLocal, imageView, ScreenHelper.getWidthPortrait(), ScreenHelper.getWidthPortrait(), listener);
        }
    }

    private static void displayResource(int urlLocal, ImageView imageView, int height, int width, RequestListener&lt;Integer, GlideDrawable&gt; listener) {
        if (imageView != null) {
            Glide.with(imageView.getContext())
                    .load(urlLocal)
                    .override(width, height)
                    .listener(listener)
                    .into(imageView);
        }
    }

    public static void displayUrl(String url, int width, int height, ImageView imageView, RequestListener&lt;String, Bitmap&gt; target) {
        config(url, imageView, width, height, target);
    }

    public static void displayUrl(String url, ImageView imageView, int width, int height, RequestListener&lt;String, Bitmap&gt; target) {
        if (!TextUtils.isEmpty(url) &amp;&amp; imageView != null) {
            Glide
                    .with(imageView.getContext())
                    .load(url)
                    .asBitmap()
                    .dontAnimate()
                    .override(width, height)
                    .listener(target).into(imageView);
            Log.d(TAG, url);
        }
    }

    public static void clear(View view) {
        if (view != null)
            Glide.clear(view);
    }

    public static void clear(Context context) {
        if (context != null)
            Glide.get(context).clearMemory();
    }
}"><pre class="notranslate"><code class="notranslate">public class ImageHelper {

    static final String TAG = ImageHelper.class.getSimpleName();

    private static void config(String url, ImageView imageView, int width, int height, RequestListener&lt;String, Bitmap&gt; target) {
        if (!TextUtils.isEmpty(url)) {
            try {
                url = UrlHelper.encodeImage(url, width, height);
                if (target == null) {
                    Glide
                            .with(imageView.getContext())
                            .load(url)
                            .asBitmap()
                            .dontAnimate()
                            .placeholder(R.drawable.ic_img_default)
                            .into(imageView);
                } else {
                    Glide
                            .with(imageView.getContext())
                            .load(url)
                            .asBitmap()
                            .dontAnimate()
                            .placeholder(R.drawable.ic_img_default)
                            .listener(target).into(imageView);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            Log.d(TAG, url);
        }
    }

    public static void displayUrl(String url, ImageView imageView, int width, int height) {
        config(url, imageView, width, height, null);
    }

    public static void displayResource(int urlLocal, ImageView imageView) {
        if (imageView != null) {
            displayResource(urlLocal, imageView, ScreenHelper.getWidthPortrait(), ScreenHelper.getWidthPortrait(), null);
        }
    }

    public static void displayResource(int urlLocal, ImageView imageView, int height, int width) {
        if (imageView != null) {
            displayResource(urlLocal, imageView, height, width, null);
        }
    }

    public static void displayResource(int urlLocal, ImageView imageView, RequestListener&lt;Integer, GlideDrawable&gt; listener) {
        if (imageView != null) {
            displayResource(urlLocal, imageView, ScreenHelper.getWidthPortrait(), ScreenHelper.getWidthPortrait(), listener);
        }
    }

    private static void displayResource(int urlLocal, ImageView imageView, int height, int width, RequestListener&lt;Integer, GlideDrawable&gt; listener) {
        if (imageView != null) {
            Glide.with(imageView.getContext())
                    .load(urlLocal)
                    .override(width, height)
                    .listener(listener)
                    .into(imageView);
        }
    }

    public static void displayUrl(String url, int width, int height, ImageView imageView, RequestListener&lt;String, Bitmap&gt; target) {
        config(url, imageView, width, height, target);
    }

    public static void displayUrl(String url, ImageView imageView, int width, int height, RequestListener&lt;String, Bitmap&gt; target) {
        if (!TextUtils.isEmpty(url) &amp;&amp; imageView != null) {
            Glide
                    .with(imageView.getContext())
                    .load(url)
                    .asBitmap()
                    .dontAnimate()
                    .override(width, height)
                    .listener(target).into(imageView);
            Log.d(TAG, url);
        }
    }

    public static void clear(View view) {
        if (view != null)
            Glide.clear(view);
    }

    public static void clear(Context context) {
        if (context != null)
            Glide.get(context).clearMemory();
    }
}
</code></pre></div>
<p dir="auto"><strong>## In My Fragment</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/**
     * needed to onStop
     **/
    @Override
    public void onStop() {
        super.onStop();
        if (viewPager != null) {
            viewPager.setListener(null);
        }
        if (noImages != null) {
            noImages.setOnTouchListener(null);
        }
        viewPager = null;
        viewPagerAdapter = null;
        
        ImageHelper.clear(noImages);
        ImageHelper.clear(mActivity);
    }"><pre class="notranslate"><code class="notranslate">/**
     * needed to onStop
     **/
    @Override
    public void onStop() {
        super.onStop();
        if (viewPager != null) {
            viewPager.setListener(null);
        }
        if (noImages != null) {
            noImages.setOnTouchListener(null);
        }
        viewPager = null;
        viewPagerAdapter = null;
        
        ImageHelper.clear(noImages);
        ImageHelper.clear(mActivity);
    }
</code></pre></div>
<p dir="auto">I have a question in regarding sharing an image via Intent Share API which was already downloaded in cache(or not in the worst case scenario). Do you have any suggestions regarding this? Would it work with the <code class="notranslate">FileProvider</code> class in the support lib? The current implementation now loads the URL in a custom target, writes the bitmap into a common file(share.jpeg) and shares that one with a custom <code class="notranslate">ContentProvider</code>. Works so far but it feels like extra unnecessary work which makes the user wait for a while for an image which is already there.</p>