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.

Performance Query - Fragments

CodeMonkeyCodeMonkey GBMember ✭✭✭

Hi all

When navigating to a new fragment, what state should I leave the previous fragment in for best performance? Will hiding the fragment and then showing it again when I popbackstack do anything for performance or is showing/hiding of fragments more expensive than just leaving them sitting under the new fragment?

Any advice appreciated


  • CodeMonkeyCodeMonkey GBMember ✭✭✭

    Sorry for the multiple posts, when adding new threads the services is reporting it is unavailable, but it must still be recording the posts.

  • Problem you'll get leaving them is that you're probably not setting a background on your layout, so you'll get elements over-laying each other as the background will be transparent.

    I found the best way was to use:

    var current = FragmentManager.FindFragmentById(Resource.Layout.layoutFrame);
    var ft1 = FragmentManager.BeginTransaction();
    ft1.Add(new MyFragment());

    I did try using .Replace() but this had some problems, I found removing and adding works a lot better for me.

    I do this with some fragments with heavy performance code in the OnResume() and this works fine, no performance problems.

Sign In or Register to comment.