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

4
  • use glide .Its more faster avoid memory issue .androidhive.info/2016/04/… Commented Dec 1, 2016 at 11:45
  • reduce your image size Commented Dec 1, 2016 at 11:47
  • guys i dont the images not loading, i just want to catch the exception fired by the image loader Commented Dec 1, 2016 at 11:47
  • Can you show your computer code? Where you are trying to load image. Commented Dec 1, 2016 at 11:57

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I personally prefer Glide over Picasso
well its totally up to you. your task is to resize image. you can do it with both i guess.
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.

Comments

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

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.