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 .androidhive.info/2016/04/…IntelliJ Amiya– IntelliJ Amiya2016-12-01 11:45:27 +00:00Commented Dec 1, 2016 at 11:45
-
reduce your image sizeRavish Sharma– Ravish Sharma2016-12-01 11:47:12 +00:00Commented Dec 1, 2016 at 11:47
-
guys i dont the images not loading, i just want to catch the exception fired by the image loadereshteghel company– eshteghel company2016-12-01 11:47:45 +00:00Commented Dec 1, 2016 at 11:47
-
Can you show your computer code? Where you are trying to load image.Junaid Hafeez– Junaid Hafeez2016-12-01 11:57:39 +00:00Commented Dec 1, 2016 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.
2 Comments
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.
Comments
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 Comment
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.