Dilemma: when to use Fragments vs Activities:

后端 未结 14 822
失恋的感觉
失恋的感觉 2020-11-22 11:58

I know that Activities are designed to represent a single screen of my application, while Fragments are designed to be reusable UI layouts with log

14条回答
  •  没有蜡笔的小新
    2020-11-22 12:07

    Thing I did: Using less fragment when possible. Unfortunately, it's possible in almost case. So, I end up with a lot of fragments and a little of activities. Some drawbacks I've realized:

    • ActionBar & Menu: When 2 fragment has different title, menu, that
      will hard to handle. Ex: when adding new fragment, you can change action bar title, but when pop it from backstack there is no way to restore the old title. You may need an Toolbar in every fragment for this case, but let believe me, that will spend you more time.
    • When we need startForResult, activity has but fragment hasn't.
    • Don't have transition animation by default

    My solution for this is using an Activity to wrap a fragment inside. So we have separate action bar, menu, startActivityForResult, animation,...

提交回复
热议问题