Thursday 5 February 2015

What is the difference between activity and fragment in android ?

fragment is a part of an activity, which contributes its own UI to that activity. Fragment can be thought like a sub activity. Where as the complete screen with which user interacts is called as activity. An activity can contain multiple fragments.Fragments are mostly a sub part of an activity.

An activity may contain 0 or multiple number of fragments based on the screen size. A fragment can be reused in multiple activities, so it acts like a reusable component in activities.

A fragment can't exist independently. It should be always part of an activity. Where as activity can exist with out any fragment in it.

No comments:

Post a Comment