If hired here at Principal Financial Group to develop iOS and Android software, when would you use a fragment rather than an activity?
In the development of apps for both iOS and Android, using code to create an activity versus a fragment is a highly debated topic to this day. For this question, your interviewer is looking to hear that you understand what the differences between the two are and when you feel that using a fragment is the proper direction to go. Make sure to speak to the high level overview of what an activity does to an app versus fragments.
"As a best practice in my development of Android apps in the past, activities are really the complete screen that a user experiences as part of the app. Fragments are really small sub activities that take place within the activity. Because fragments within an app have their own life cycle and receive their own input events within the app, there are specific times where fragments make the most sense to use in development. In my experience, I always use fragments when the app is working with UI components that are going to be uses across multiple activities within the app. As well, fragments have also served very well when using swipe views within the app."
