This question has already been answered:

When should I create activations and when should I use fragments?

Sample application:

I will have a map with location definitions, before that I want to make a loading screen while the map is immersed. After the address is determined, there will be a button for placing the order (there will be a form for this). Then you can see where the machine is moving with the orders. There will also be a registration window if the user is not registered.

How to organize it all right? What principle of construction should a window be?

I want to use the Navigation Drawer Activity and I can’t understand that I need to create a new activation and about 5 xml files for each window (settings, order form, registration, map, etc.) or create one activation for 10 windows and try to shove everything into a fragment.

Reported as a duplicate by the participants of Vladyslav Matviienko , katso , pavlofff , aleksandr barakin , sercxjo 17 Apr '16 at 19:57 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    2 answers 2

    What and how to use the programmer chooses depending on the task. You can make an application similar to yours from both several activities and from one activity and several fragments.

    An activity is an entity representing an application screen. There may be several of them, and they can change, transfer data between themselves. An application screen can contain several typical elements (like a puzzle) and it’s more convenient to make these elements on the basis of fragments. A fragment on the phone can occupy the entire screen, on the tablet there can be several fragments on the screen, which gives the interface flexibility.

    Fragments on the use of resources and ease of operation easier and easier activity. And in my experience to organize navigation and changing screens using fragments is much more convenient. With this model, the activity is a container in which several fragments are displayed and changed.

    Fragments do not interact with each other. All interaction is carried out through the activity. Mechanisms of interaction may be different. Personally, I find it more convenient to equip the interaction through interfaces. I usually have all the interaction mechanisms specified as protected in the class inherited from Fragment (you can call it BaseFragment or MyFragment or something else) and all other application fragments are inherited from it and use these interaction mechanisms as their own without duplicating the code.

    We should also note that there are also other points of view regarding the Activity and fragments. There are articles in which people are encouraged to use fragments as rarely as possible. You just have to try both and understand that it is more convenient for you personally.

    PS And I still recommend reading this: Fragments

    • why advise to use fragments less often, or you can ssylochku, interesting! - Kirill Stoianov
    • one
      I went to get a reference and did not find it. As far as I remember in those articles, they rested on the complexity of working with backstack and that it’s better to use presentation widgets for which you can write your backstack yourself. I concluded that people simply do not know how to cook them (fragments). In the earlier versions of the fragments, there really were a lot of problems, according to the latest version of the support library, in terms of fragments, it works quite stably. - Shutko Alexander

    I agree with the opinion of the author from the answer above, that the programmer himself must determine this very balance between the use of activation and fragments.

    Using activit without fragments in some sense may be easier. elements that are in the activation can communicate with the activation and other elements in it - directly, on the other hand - nothing prevents you from using Callbacks to communicate fragments with the activation, which in turn can make your code more universal.

    Also the choice may depend on the task. For example, there are activations in which there are 4 tabs - it makes sense to make them fragments, since they can be repeatedly reused in the process of use, if necessary, you can write interfaces for communicating with activations and thus you can get independent elements that can communicate between themselves and can then be used elsewhere, because They are not tied to one particular activite.