Is having a fragment with every activity a good practice (based on Android Studio)?

前端 未结 1 428
忘了有多久
忘了有多久 2021-01-13 07:52

In the new Android Studio, every time I create an activity from the wizard it will create the following structure:

public class LoginActivity extends Activi         


        
相关标签:
1条回答
  • 2021-01-13 08:48

    Generally speaking, yes, you should try to use fragments as much as possible, so that you can have different layouts for different size / aspect ratio devices.

    And yes, that's why Android Studio generates code that way by default.

    However, like any good rule, there are exceptions. Sometimes, an activity is simple, and will not differ on different devices. In that case, a fragment doesn't necessarily make sense.

    In short, use fragments by default. Go with just an activity in the few cases where it makes sense you in your project.

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