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
Adrian

Posts

  • 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.AddToBackStack("NAME");
    ft1.Remove(current);
    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.