1

So, i have some problems with my Xamarin.Forms app. I am getting "Java.Lang.OutOfMemoryError" when I am trying to await ViewExtensions.LayoutTo.

I have tried to increase Java Heap size up to 2G, but it did not help.

public class SplashPage : ContentPage
    {
    public SplashPage()
        {
            NavigationPage.SetHasNavigationBar(this, false);

            AbsoluteLayout layout = new AbsoluteLayout();
            Content = layout;

            Image image1 = new Image
            {
                Source = ImageSource.FromFile("image1.png"),
            };
            layout.Children.Add(image1);

            Image image2 = new Image
            {
                Source = ImageSource.FromFile("image2.png"),
            };
            layout.Children.Add(image2);

            Image image3 = new Image
            {
                Source = ImageSource.FromFile("image3.png"),
                Scale = 0.5,
            };
            layout.Children.Add(image3);

            layout.SizeChanged += async (s, e) =>
            {
                AbsoluteLayout.SetLayoutBounds(image1, new Rectangle(0, 0, image1.Width, image1.Height));
                AbsoluteLayout.SetLayoutBounds(image2, new Rectangle(0, ((AbsoluteLayout)s).Height, image2.Width, image2.Height));
                AbsoluteLayout.SetLayoutBounds(image3, new Rectangle(-image3.Width, ((AbsoluteLayout)s).Height - image3.Height - 5, image3.Width, image3.Height));

                // I have placed those animations in SizeChanged event because i needed to get actual size of layout (outside this event it would be incorrect)
                await ViewExtensions.LayoutTo(image2, new Rectangle(0, ((AbsoluteLayout)s).Height - image2.Height, image2.Width, image2.Height), 2300);
        // here Java.Lang.OutOfMemoryError
                await ViewExtensions.LayoutTo(image3, new Rectangle(((AbsoluteLayout)s).Width, ((AbsoluteLayout)s).Height - image3.Height - 5, image3.Width, image3.Height), 3000);

                await Task.WhenAll(
                    image2.FadeTo(0, 700), image1.FadeTo(0, 700));

                Application.Current.MainPage = new NavigationPage(new LoginPage());
            };
        }
    }
1
  • Do you mean when you run this code you get the OutOfMemoryError? I test the code without errors. Could you provide more information for me to reproduce? Code sample would be helpful. Commented Oct 25, 2019 at 6:50

1 Answer 1

1

Try this way to increase your app's heap size in your AndroidManifest.xml:

<application android:largeHeap="true"></application>
Sign up to request clarification or add additional context in comments.

1 Comment

Also, I would not recommend to set Java Heap size to 2G, I would go with 1G. In other cases, maybe think about optimizing app esources.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.