May 17, 2016

In this tutorial I’m going to show you the differences between android.app.Fragment and android.support.v4.app.Fragment. Nowadays whatever applications are being made they all use Fragments. Using Fragments we make our applications smoother. However our IDE shows two option when we use the Fragment, one is android.app.Fragment and the other is android.support.v4.app.Fragment. The question arises which to use when.
Below I’m listing out few of the differences between android.app.Fragment and android.support.v4.app.Fragment

  1. android.app.Fragment was introduced in API Level 11. So if we use android.app.Fragment, we will not be able to make an app for below API 11.
  2. If we are using Fragments and want to work in all devices, then we should stick to the android.support.v4.app.Fragment. However, if we are targeting devices running API 11 or above then we should use android.app.Fragment.
  3. Suppose in our application we have to use ViewPager then we cannot use android.app.Fragment, then we should stick to the support library.
  4. However, if the requirement is to use android.app.Fragment and ViewPager together, then we have to use “android.support.v13.app”. Here we have to use v13 support jar.
  5. If in our application we are using Fragments and that Fragments contain other fragments then we should only use “android.support.v4.app.Fragment” Here the support library will give us a support version of the child fragments manager.