Do fragments cause fat activities?

前端 未结 1 1005
萌比男神i
萌比男神i 2021-01-18 08:52

Recently I was given the task of building an app which is rather like a book. The high-level design was basically a couple of list views showing chapters, then drill-down in

相关标签:
1条回答
  • 2021-01-18 09:07

    does the combination of several fragments and animations lead to fat Activities?

    Yes. However, that is becoming more common, and therefore less code smelly.

    What is somewhat smelly is that loooooooooooooooooooong list of interfaces. :-)

    For something that complex, you might find that using an event bus (Square's Otto, greenrobot's EventBus, or even LocalBroadcastManager) is a cleaner approach. Rather than having fragments use an interface to tell their hosting activity about an event (which is my guess as to the source of all your interfaces), the fragment can post an event to the bus, which the hosting activity can subscribe to. This does add a smidge of runtime overhead, but adds the benefit of avoiding all the interfaces. It can also be extended to other components, such as a service posting an event when something happens in the background that the UI layer, if it exists, needs to know about.

    0 讨论(0)
提交回复
热议问题