How Fragments affect the Activity “single, focused thing that the user can do” principle?

前端 未结 1 1959
你的背包
你的背包 2021-02-14 05:43

As Android documentation states: \"An activity is a single, focused thing that the user can do.\"

However with Fragments we will be able to do many \"things\" within the

1条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-14 06:06

    Should I have one Activity to manage all the application fragments and fragment transactions?

    That is impossible to answer in the abstract. However, most applications will have multiple activities, even in a fragment-based world. Some of that will be to accommodate smaller screen sizes, where it will tend to be one fragment per activity. Some of that will be required by the framework (e.g., inheriting from PreferenceActivity). And, some of that will be by GUI design.

    Thus breaking with the "single, focused thing that the user can do" principle for Activities?

    That portion of the documentation was written in 2008, perhaps earlier. Had fragments existed back then, I imagine the documentation would state that a fragment is a "single, focused thing that the user can do", with activities serving as an orchestration layer, determining what fragments are visible in what circumstances.

    The documentation will not in all places be updated to reflect fragments, and even if it does, it will take some time. For the balance of 2011, at minimum, you will need to perform your own translations of 2008-era instructions to convert them to 2011-era fragment-based UIs.

    Lets say now I have to adapt it to Fragments and large screens... and that I don't want to create a second application, neither have two completely different logics (one for phones other for tables) inside one application.

    I have no idea what you consider "completely different logics" to be. In a fragment-based app, most of your business logic will be in the fragments themselves. The activities, again, serve as an orchestration layer, determining what fragments should be visible and coordinating event handling. The latter will get a bit more complicated than it used to be, since sometimes clicking on an item in a list will bring up a new fragment and sometimes clicking on an item in a list will start a new activity, depending on screen size.

    Or am I missing something?

    To be honest, you are missing enough concreteness to your question to make it reasonably answerable.

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