Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between support-v4.app.fragment and app.fragment?

Tags:

android

I am new to fragments and had a question: When I updated my SDK tool and went to create a project(min = api8, the default one), I noticed the android-support-v4.jar in my Referenced Library.

When I extended my class and tried to use the Fragment class, I found out there are 2. One is android.app.Fragment and other is android.support.v4.app.Fragment. What is the difference between these two?

like image 933
qwr qwr Avatar asked Aug 02 '12 00:08

qwr qwr


People also ask

What are APP fragments?

According to the Android documentation, a fragment is a part of applications user interface that is bound to an activity. Fragments have their lifecycle and layouts or UI components. Fragments help enrich your UI design, pass data between different screens, and adapt to different device configurations.

What is a fragment in Android app?

A Fragment represents a reusable portion of your app's UI. A fragment defines and manages its own layout, has its own lifecycle, and can handle its own input events. Fragments cannot live on their own--they must be hosted by an activity or another fragment.

Is Android fragment deprecated?

This class was deprecated in API level 28. Use the Support Library DialogFragment for consistent behavior across all devices and access to Lifecycle. This class was deprecated in API level 28.

Is Android a fragment?

Android Fragment is the part of activity, it is also known as sub-activity. There can be more than one fragment in an activity. Fragments represent multiple screen inside one activity. Android fragment lifecycle is affected by activity lifecycle because fragments are included in activity.

What is Android support V4 fragment?

android.support.v4.app.Fragmentis the Fragmentclass in the android support library, which is a compatibility package that allows you to use some of the newer features of Android on older versions of Android. android.app.Fragmentis the Fragmentclass in the native version of the Android SDK. It was introduced in Android 3 (API 11).

What is fragment in Android?

android.app.Fragment is the Fragment class in the native version of the Android SDK. It was introduced in Android 3 (API 11). If you want to make your app use fragments, and want to target devices before API 11, you must use android.support.v4.app.Fragment.

Can I use fragments on Android devices before API 11?

If you want to make your app use fragments, and want to target devices before API 11, you must use android.support.v4.app.Fragment. However, if you're only targeting devices running API 11 or above, you can use android.app.Fragment.

When to use support fragments instead of native fragments?

Use the Support Library Fragmentfor consistent behavior across all devices and access to Lifecycle. So support fragments (android.support.v4.app.Fragment) should be used everywhere instead of native fragments(android.app.Fragment) now. Share Follow edited Aug 23 '18 at 11:41


1 Answers

If you're developing for Android 3+, you can use app.Fragment.

However, in 3-, Fragments didn't exist yet. That is where the support library comes in. It provides Fragments for older versions of Android.

See also this link

like image 56
nhaarman Avatar answered Oct 27 '22 00:10

nhaarman