Nested snippets of bad practice?
I am creating my application. I try to follow all Google guidelines. Most of the user interface is Fragment
. It's really cool, making the interface look slicker and more beautiful. It is of course better to split my screen into separate logical UI pieces that can later be reused in a different way. Fragments are lighter than Activities
. Animation between slices is smoother and looks better.
All perfectly. How to use one Activity
per app?
According to Eric Burke , you should use Fragment whenever you can. Here's a lecture - Android App Anatomy .
Of course, using one Activity
for a complete application can bring certain benefits.
But there are of course some downsides.
Consider a simple application, this is not a real application, but only, for example.
Here are three screens.
This is not exactly the same user interface as in my application, just to make it easier to understand my question.
There are several ways to create such a user interface.
- Each screen is a single activity with its own layout.
- Each screen is again a single activity, but all fragments are fragments, for example, on the first screen. This will be three fragments: ViewPager, Horizontal List and Custom View. The second screen will only contain one fragment,
Recycler View
and so on. - Using activity for all screens. In this case, we also have several ways.
a) Use one Fragment container for the whole screen and all widgets will be part of one Fragment. b) Use a single container fragment, but with nested fragments.
c) Use fragments without a container and replace all or some of them when we need to change the UI, for example, to change the interface from the first screen to the second, we need to remove all fragments from the first screen and add one new fragment (list view) because on these two screens we don't have the same UI parts.
In general, I cannot decide for myself what and when to use, which is best in accordance with the current guidelines, which can bring the user a better experience.
I'm worried about nested snippets, but if it was bad practice, I guess Google won't add such a feature to the framework. So it might be an acceptable way.
I want to understand where is the best use of Activity, Fragment or some mixture of them. There is no problem with writing code for all of these cases, but the main goal is to follow the best practices for building software architecture.
I would be very grateful to everyone who can help understand this topic. Thanks to everyone who read this to the end and to those who can help me with this issue.
source to share
No one has answered this question yet
Check out similar questions: