What are the differences between activity and fragment?

Main Differences between Activity and Fragment

  1. Activity is an application component that gives a user interface where the user can interact. The fragment is a part of an activity, which contributes its own UI to that activity.
  2. For Tablet or if mobile is in landscape then Using fragment we can show two lists like the only list for show the state name and other lists will show the state description in single activity but using Activity we can't do the same thing.
  3. Activity is not dependent on fragment.but The fragment is dependent on Activity, it can't exist independently.
  4. without using fragment in Activity we can't create multi-pane UI. but using multiple fragments in a single activity we can create multi-pane UI.
  5. If we create a project using only Activity then its difficult to manage but if we use fragments then the project structure will be good and we can handle it easily.
  6. An activity may contain 0 or multiple numbers of fragments. A fragment can be reused in multiple activities, so it acts like a reusable component in activities.
  7. Lifecycle methods are hosted by OS. The activity has its own life cycle. Lifecycle methods in fragments are hosted by hosting the activity.
  8. For Activity, we just need to mention in Manifest but for fragment its not required.
  9. Activity is not lite weight. The fragment is the lite weight.

As per the android developer documentation, difference between fragment & activity in their life cycle.

Doc link http://developer.android.com/guide/components/fragments.html#Lifecycle

The most significant difference in lifecycle between an activity and a fragment is how one is stored in its respective back stack. An activity is placed into a back stack of activities that's managed by the system when it's stopped, by default (so that the user can navigate back to it with the Back button, as discussed in Tasks and Back Stack). However, a fragment is placed into a back stack managed by the host activity only when you explicitly request that the instance be saved by calling addToBackStack() during a transaction that removes the fragment.

Otherwise, managing the fragment lifecycle is very similar to managing the activity lifecycle. So, the same practices for managing the activity lifecycle also apply to fragments. What you also need to understand, though, is how the life of the activity affects the life of the fragment.

& for multi pane layouts you have to use fragment that you can't achieve with activity.


Activity is the UI of an application through which user can interact and Fragment is the part of the Activity,it is an sub-Activity inside activity which has its own Life Cycle which runs parallel to the Activities Life Cycle.

Activity LifeCycle                           Fragment LifeCycle
onCreate()                                     onAttach()
    |                                              |
onStart()______onRestart()                     onCreate()
    |             |                                |
onResume()        |                            onCreateView()
    |             |                                |
onPause()         |                            onActivityCreated()
    |             |                                |
onStop()__________|                             onStart()
    |                                              |
onDestroy()                                    onResume()
                                                   |
                                                onPause()
                                                   |
                                                onStop()
                                                   |
                                              onDestroyView()
                                                   |
                                               onDestroy()
                                                   |
                                               onDetach()

Those are two completely different things:

An Activity is an application component that provides a screen, with which users can interact in order to do something. More details: https://developer.android.com/guide/components/activities/intro-activities

Whereas a Fragment represents a behavior or a portion of user interface in an Activity. https://developer.android.com/guide/fragments