1.

When should you use a Fragment, rather than an Activity?

Answer»

In Android, UI is representing as an Activity. Single Screen in an application represents as Activity while FRAGMENTS are reusable UI with business logic. Activity is a collection of Screen. In android application, Fragments are using in Navigation DRAWER in our entire screen. You can also use fragment to display Google Map on screen.

Following are important POINTS about a fragment:

  • The fragment life cycle is closely related to the LIFECYCLE of its host activity.
  • A fragment can implement a behaviour that has no user interface component.
  • A fragment has its own layout and its own behaviour with its own lifecycle callbacks.
  • You can add or remove fragments in an activity while the activity is running.
  • You can combine multiple fragments in a single activity to build a multi-pane UI.
  • A fragment can be used in multiple activities.
  • When the activity is PAUSED, all the fragments available in the activity will also be stopped.


Discussion

No Comment Found

Related InterviewSolutions