I have this application that loads images from a web service using the image loader 1.9.3 library and with having phones with low memory the image loader gives out of memory exception that is only visible in the log cat. I don't mind the exception but i want the exception to be visible to the user via a toast so that he knows why the images stopped loading. Any ideas please
-
use glide .Its more faster avoid memory issue .http://www.androidhive.info/2016/04/android-glide-image-library-building-image-gallery-app/ – IntelliJ Amiya Dec 01 '16 at 11:45
-
reduce your image size – Ravish Sharma Dec 01 '16 at 11:47
-
guys i dont the images not loading, i just want to catch the exception fired by the image loader – eshteghel company Dec 01 '16 at 11:47
-
Can you show your computer code? Where you are trying to load image. – Junaid Hafeez Dec 01 '16 at 11:57
3 Answers
your images are too big compared to size of your ImageView
.
I recommend you to use Picasso.
with this you can Resize your Image according to your need.
Picasso.with(this).load(image_link)
.resize(100, 100)
.placeholder(R.drawable.placeholder)
.error(R.drawable.placeholder)
.into(imageView);
Happy Coding.

- 5,518
- 9
- 31
- 50
-
I personally prefer [Glide](https://github.com/bumptech/glide) over Picasso – EpicPandaForce Dec 01 '16 at 12:08
-
well its totally up to you. your task is to resize image. you can do it with both i guess. – V-rund Puro-hit Dec 01 '16 at 12:13
Maybe your images are to big when you downloaded them. A single image with 800 x 600 pixels will be less than 100kb when it comes as JPG as it is compressed. However, when you decode it into an bitmap it will become approx. 2MB of data. When you load 80 books, you will get 160MB of data very soon. Mabye you should load less books (20) or reduce the size of your images from the server.
Usually, logcat prints an Exception which will show you what causes the OutOfMemoryException. When I got this exception it was always caused by too big or too many pictures at a time.

- 207
- 2
- 14
Try to add
android:largeHeap="true"
in your mainfeist file app->Src->Main folder
<application
android:name="com.xxxxxxxxxxxxxx"
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/myAppTheme">
<activity
android:name="com.xxxxxxxxxxxxxx"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
To decode file you can use this https://stackoverflow.com/a/823966/4741746
The solution work for me is https://stackoverflow.com/a/13226245/4741746
Let me know if not woking

- 1
- 1

- 3,647
- 3
- 35
- 55
-
It's funny because the `android:largeHeap="true"` is actually a good idea. I've seen Xiaomi devices say "out of memory error" for totally normal images that were already resized by Glide. – EpicPandaForce Dec 01 '16 at 12:25