Recently learning android-architecture-samples, I found that each activity uses fragment, even if the activity doesn't really need fragments, in my opinion, this makes the activity lazy and leads to a lot of files.
For example, TaskDetailActivity sets the Toolbar, and other view work is given to the TaskDetailFragment.why use a fragment instead of the activity to achieve, you will find that the entire demo is doing this, I don't think this is a meaningless question. There must be reason to do so.
Can anyone tell me why I wrote this, what are the benefits? Thank you!
No. You can have activity without a fragment.
So why Google and other Android developer advocates are pushing for a single-activity-multiple-fragments architecture?
It's because, this way you can have multiple screens (fragments) share the one single activity which otherwise would be so hard to manage as many number of activities as number of screens in your app. Fragments can easily be added and popped from your activity's fragment backstack so there's a flexibility of sharing resources from a same activity with multiple fragments. Also, if you don't care about differences in the different screens in terms of configuration such as orientation etc. , It's much easier to manage multiple screens in one single container.
From my experience you should create different activities for different workflows. E.g. your whole app (core features of your app) can sit in one activity however other things like sign up, login, onboarding can be activities of their own. This way you can start one single workflow by starting a new activity.
Another good example for choosing activity over a fragment when you are adding a new screen - Your new screen has completely different configuration than other screens (fragments) that are shared within your current activity. E.g. your new screen is a photo / video gallery that requires you to support both the orientations (landscape and portrait) but your other screens in your existing / current activity can only be portrait.
I hope you have a good clarity on why people are leaning toward single-activity-multiple-fragments approach.