Android Jetpack: How fragment usage is affected by new components (Google I/O '18)

https://www.youtube.com/watch?v=WVPH48lUzGY&t=1044s

So over time, Fragment APIs have kind of evolved. And as of the release of Architecture Components, a lot of people have been asking us questions like, how do all these things fit together?

最开始引入并设计 Fragment API 的原则

So Fragments were really designed to make sure that you could do one thing, and that was to allow splitting up these huge activity classes. This was something that, again, we were seeing the pain that developers were feeling that their activity classes were getting really big and hard to manage. So we wanted to see, could we allow for you to decouple some of the various things that your activity classes are doing to sort of relieve a little bit of that pressure? So that means that anything a Fragment can do-- or anything an Activity can do, a Fragment had to be able to do, too. And that guided a whole lot of the API design from the beginning.

You may have a couple of fragments in here that kind of have their own specific requirements and their own specific UI. And your activity just becomes more of a shell for this.

Things Fragment do

Architecture Components -- Doing one thing well

we kind of took a more holistic approach to how we do APIs. And this really kind of started with a lot of the work we did on architecture components. So all of the architecture components have really tried to focus in on doing one thing well rather than being kind of the kitchen sink kind of approach. So for example, lifecycle observers-- the ability to have lifecycle, and that on resume, on start, as kind of a piece that is completely independent from other things, something that you can register just if you care about lifecycle. Similarly for a ViewModel, we created a new primitive, a new object, specifically for that kind of retained instance state or cross configuration changes. And of course, this year, just yesterday, we announced a new navigation architecture component. Kind of working out the much higher level architecture on how you build your UI and put these things together and really trying to tackle just the specific problem of how do you move from one screen to the next screen. So all these things were kind of really focused on doing one thing well. And we're trying to bring a lot of that to Fragments. But that means that we kind of have a lot of legacy to go along with that.