Answer the question
In order to leave comments, you need to log in
Question about activity and fragment in android?
Please explain what is used for what.
Why, for example, is it impossible / possible to create one activity and then just change fragments? Or why it is impossible/possible to create a bunch of activities without fragments?
From what I read, I understood only one use of fragments - modularity. For example, we created one navigation drawer and can use it in different activities.
Answer the question
In order to leave comments, you need to log in
Fragments are good when the application is launched on different platforms with different resolutions, for example, there is an application with a menu and content, and so - fragments allow you to do so that -
on small screens, so that the menu is displayed first and shows content when pressed, but on large screens so that the menu is displayed on the left and the content on the right, which is very convenient.
Fragment - a piece that can be done once, and then used in different places)
Use snippets where possible.
For example, for grouping functionality (fragment1 - a list of articles on the resource, and fragment2 - the articles themselves) they will have a common activity. Further, when implementing the tablet display mode, you can very simply organize the UI.
Good application example
And who said that it is impossible? You can create one activity and change fragments. Technically it's perfectly acceptable. Before 3.0, in general, everything was built only on activation. So it's very possible. You need to look at what is more convenient and expedient.
This is a violation of the SOLID principles.
You will have a lot of implementation in one class + you yourself will get confused (tormented) with BackStack.
P.s. or write your activity as in Telegram.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question