Are Fragments and Fragments active faster than Actions?

Are Fragments and Fragments active faster than Actions?

If I don’t need to load my activity into fragments, should I use FragmentActivities and Fragments over Activities?

The reason I'm asking for is because I have been using actions exclusively for many years, and the Facebook SDKs as well as Google Maps 2.0 made me use fragments, and now I wonder if they are inherently “better” "or not, compared to some other implementation.

If this is “unconstructive” or “too open”, then the answer is obviously no. But if there are any documents or a Google developer blog on this particular subject, I would like to know about it

+6
source share
3 answers

In my last application, I became a supporter of fragments. Regardless of whether faster or faster, they are calculated faster, they feel faster because you can change them instantly and include them, including full back stack support if you do it right (call addToBackStack () in a transaction or something very similar).

Now I use the Fragments / Fragment function for the whole navigation, which I want to feel very quickly, for example, clicking on a line to get more detailed information. I just start new actions when I want to do a fundamentally different thing and have a clean slate for work. For example, I usually have a LoginActivity function that deals exclusively with logins / registrations and at least one more, which is the core of the application.

But the fundamental benefit of the Fragments is still their flexibility. I can show fragments on top of other fragments, rearrange them on different screen sizes, etc. But there are other benefits. It takes some time to feel natural (just as you did at the beginning of the class).

One caveat, I always regret putting fragments in my layouts. I cannot name the exact reasons here, but essentially you are just losing some flexibility. Instead, I create a normal layout for each fragment and add a placeholder view in the activity layout, programmatically create the fragment and use transaction.replace () to add it to the layout. Perhaps because this is the main way to exchange fragments inside and outside this space, and I prefer to just have one way to do things where possible.

+10
source

Yes, fragments are introduced solely to support large screens for efficient use of the area. Fragment processing is very simple in terms of memory. But nested fragments create problems.

+1
source

Snippets are very useful if you want to split the screen. This way you can have different views on one screen. Another way to use fragments is to say that you have tabs for categorizing elements. Could have clothes, shoes as tabs. On each tab there will be a fragment for storing products. Tabs can either be held in activity or in a fragment. I find fragments a little faster than actions, but this is not really what you would really notice in most cases. Regardless of whether they were designed for speed or not, they still seem / feel a little faster.

The downside of using snippets is that certain callbacks, such as onBackPressed, only relate to activity. Fragments do not have access to this. I often find everything possible to minimize as much as possible. Also do not forget that Activities are not just views, they are also a screen. While the fragment is only a representation and does not have a screen. toolbars / actions, etc. also apply only to actions, but if you use a special toolbar, you can use it in a fragment, implementing onTouch (if not a button, but some object) or onClick (buttons), the method for them will give you what you need . So there really are some flaws, but at least some of them are almost bypassed.

I agree that the transition of the fragment is amazing and pushes the stack when working with buttons with feedback and onBackPressed. Trick.

I always use the switch in parenting activity, etc., to see which fragment should be in sight, I often update it with the interface transfer package, etc. Not sure if anyone else has found a more efficient way or not. But I really find it useful when switching views.

Yep fragments are the best brass for most things.

0
source

Source: https://habr.com/ru/post/944581/


All Articles