0

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

eshteghel company
  • 471
  • 1
  • 7
  • 22

3 Answers3

1

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.

V-rund Puro-hit
  • 5,518
  • 9
  • 31
  • 50
0

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.

Ravish Sharma
  • 207
  • 2
  • 14
0

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

Community
  • 1
  • 1
Sushant Gosavi
  • 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