What is the difference between a fragment and an activity? Explain the relationship between the two.

1 votes
169 views
Harsh kumar srivastava asked 10-Jan-2018 in Technology by Harsh kumar srivastava

What is the difference between a fragment and an activity? Explain the relationship between the two.

1 Answer

0 votes
Prateek sharma answered 10-Jan-2018 by Prateek sharma

What is the difference between a fragment and an activity? Explain the relationship between the two.

fragments are the part of the activity which helps in the development of the UI.

a user interacts with the complete screen which is known as the activity.
an activity may contain multiple fragments. these fragments can be used in multiple activities which means that the fragments are the reusable components of the activity.
a fragment cannot exist without an activity whereas an activity does not necessarily contain a fragment.