What is the meaning of fragments in Android?

What is the meaning of fragments in Android?

Author: DarkJin, 2014-04-10

3 answers

To understand the meaning of templates, imagine a classic situation with a news reader. On the phone, it will look like one activity with a list and one-the actual news. On the tablet, where the screen is larger, you can place these two activites side by side. And in order not to do the same work twice, you can simply make two fragments and place them on the activity.

Fragments are "high-level widgets".

There are also fragments in delphi. They are called " frames" (the TFrame class).

 5
Author: KoVadim, 2014-04-10 20:12:20

They have another awesome feature - setRetainInstance (boolean). This allows you to bypass some of the limitations of the lifecycle activity and save data/logic directly in fragments. In other words, when this flag is set, the fragment is not destroyed as an activity, but is stored until the program exits. Well, DialogFragment will allow you to quite simply add your own View for the dialog box.

 2
Author: arg, 2014-04-10 20:52:18

Fragment-is a modular part of the activity. For the architecture in Android, it is convenient to perceive it as a continuation of the main View, sometimes called a SubView. The fragments in the of docks are very well described: https://developer.android.com/guide/components/fragments.html?hl=ru

The meaning of fragments and their main advantage was originally that you can show 2 fragments on 1 Screen. But you can't show 2 Activity in 1 Screen, it's not possible (except multiprocesses, MultiWindow). Later, this approach in MaterialDesign was named as the correct organization of intefrays and navigation and the name of its MasterDetailFlow. This concept is very convenient to organize through fragments. Otherwise, you would have to write a separate logic for the additional situation, and support both parts, which is very bad.

Now Fragments in Android are an integral part of the development of full-fledged applications, and they are used by the system with the API 3.0. Fragments allow you to create a more convenient View decomposition, they are easily replaceable in Activtiy, and can easily move to other projects. Only with the help of fragments you can properly organize ViewWidgets: NavigationView, DrawerLayout, NavigationBottom, BottomSheet, FragmentsDailogs, ViewPagers, etc. (you can end up without it, but sometimes it is difficult or very difficult) You can create beautiful transitions and animations on the same page, and sometimes (Transitions) you can only use fragments.

 1
Author: Shwarz Andrei, 2017-10-04 15:02:47