search

Home  >  Q&A  >  body text

android - 只有一个视图时需要使用fragment吗

一个activity,整个全部用fragment填充,和直接用activity绘制,占用上有差距吗?如图

大家讲道理大家讲道理2891 days ago421

reply all(7)I'll reply

  • 黄舟

    黄舟2017-04-18 09:06:31

    The description of the question is not detailed enough. It can be analyzed from several aspects:

    1. View drawing efficiency: There should be no difference
    2. Page loading speed: Single Activity is obviously higher than Activity using Fragment, because Fragment requires FragmentManager & ChildFragmentManager to maintain them;
    3. Memory overhead: Single Activity is obviously smaller.

    The above three points can be verified through the tools that come with the Android development environment.

    p.s. @zzxxasp has made it very simple and clear about the usage scenarios of these two.

    reply
    0
  • 阿神

    阿神2017-04-18 09:06:31

    If the questioner wants to ask about memory usage, it will definitely take up more than pure activity. After all, there are more memory objects, so there is nothing to say. The key is what your usage scenario is, a view or a direct activity.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:06:31

    Activity is more efficient than Fragment. Because Activity can be used alone, but Fragment must be placed in Activity to use. If there is a single view, I think it is better to use the activity directly. If there are multiple switches, such as the 3 buttons under QQ WeChat to switch views, it would be better to use fragments

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:06:31

    The purpose of using Fragment is to separate logic to facilitate development and management. If using a single Fragment can make the logic clear and simplify the original Activity code, a single Fragment is not impossible.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:06:31

    Just use a separate Activity to save code.

    reply
    0
  • 阿神

    阿神2017-04-18 09:06:31

    This depends on the needs. The function of Fragment is to extract and manage the parts of the activity independently. And Fragment has its own life cycle, so it is not that complicated when the functions are subdivided. I have also seen using view before To implement the functions of Fragment.

    reply
    0
  • 黄舟

    黄舟2017-04-18 09:06:31

    For a cake, is it more expensive to have one layer of packaging box or two layers of packaging box?

    reply
    0
  • Cancelreply