I am creating my app. I am trying to follow all google's guidelines. There is a great part of UI - Fragment
. It is really great thing that makes UI smoother and prettier.
Of course it is better to split my screen into separate logic portions of UI which can be later reused in another activity, layout whatever...
Fragments are more lightweight than Activities
. Animation between fragments is smoother and looks better.
All that is great. What about using one Activity
per app ?
According to the Eric Burke You have to use Fragment whenever you can do this. Here is the lecture - Android App Anatomy.
Surely, using one Activity
per full app can bring some benefits.
But of course there are some cons.
Let's consider simple app, it is not real app ,but just for example.
Here are three screens.
It is not exactly the same UI as in my app, just for make it easier to understand my question.
There several ways we can follow to build such UI.
- Each screen is single activity with it's own layout.
- Each screen is again single activity but all portions are fragments, for instance on the first screen. It will be three fragments : ViewPager, Horizontal List and Custom View. Second screen will have only one
Recycler View
fragment and so on. - Use on activity for all screens. In this case we also have several ways.
a) Use one container Fragment for whole screen and all widgets will be the part of one fragment layout.
b) Use one container Fragment but with nested fragments.
c) Use fragments without container and replace them all or some of them when we need to change UI, for example to change UI from first screen to the second we need to delete all fragments from the first screen and add one new fragment (list view), because we don't have the same parts of UI on these two screens.
All in all, I cannot decide for myself what and when to use, what is better according to the current guidelines, what can bring user better experience.
I am worrying about nested fragments, but if there was a bad practice, I think, google wouldn't add such feature into the framework. So may there is acceptable way.
I want to understand where it is better use Activity,Fragment or some mixture of them. There is no problem to write code for all this cases, but the main goal is to follow the best practices in building software architecture.
I will be really grateful for anyone who can help to understand this topic.
Thanks everyone who have read this to the end and those who can help me with this question.
Aucun commentaire:
Enregistrer un commentaire