Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

App crashes while displaying 228 KB imges

MFarMFar EGMember

Hi all. I have a problem displaying two images on the same Activity on a Xamarin.Android app, I pass a bundle to an Activity, the bundle contains the the images' id.
the code in my activity:

    protected override void OnCreate(Bundle savedInstanceState)
        var viewModel = this.Intent.GetBundleExtra("VM");

        this.FindViewById<TextView>(Resource.Id.type).Text = viewModel.GetString("NAME");
        this.FindViewById<TextView>(Resource.Id.area).Text = viewModel.GetString("AREA");
        this.FindViewById<TextView>(Resource.Id.left_subscript).Text = viewModel.GetString("LSS");
        this.FindViewById<TextView>(Resource.Id.right_subscript).Text = viewModel.GetString("RSS");

        this.FindViewById<ImageView>(Resource.Id.catalog_villa_front).SetImageResource(viewModel.GetIntArray("IMAGES")[0]);     //Here is the exception is thrown

the exception message:

Java.Lang.OutOfMemoryError: Failed to allocate a 640012 byte allocation with 177720 free bytes and 173KB until OOM

the two images are very small in size (200px * 200px, 24bpp) which are roughly 235 KB , I can''t see why it need to allocate 640012 Byte (625 KB), and even if it needs 625KB how is it possible that my 1GB-ram device has no space for it?

Note: I tried the Max Heap Size trick but i still have the problem, any help would be greatly appreciated. Thanks for your time.


  • Nani_777Nani_777 INMember ✭✭

    copy those images to all the drawable folders including hdpi xhdpi xxhdpi

Sign In or Register to comment.