Difference between android.app.Fragment and android.support.v4.app.Fragment
android.support.v4.app.Fragment
is the Fragment class 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.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
. However, if you're only targeting devices running API 11 or above, you can use android.app.Fragment
.
Edit: the OS-contained android.app.Fragment
is now deprecated (as of API level 28), and everyone should move to using the support library implementations.
Difference between support-v4.app.fragment and app.fragment?
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
android.support.v4.app.FragmentManager OR android.app.FragmentManager?
First of all: your activity should extend FragmentActivity.
About support libraries. They were introduced to add some functionalities to older Androids. For example Fragments were introduced in Android 3.0 (SDK nr: 11). In fact (according to documentation) in Androids 3.0 < support libary uses system implementation of Fragments.
Confused by android.support.v4.app.FragmentActivity and android.app.FragmentTransaction
All the apps I write need to support right back to Android 2.3 and this is the easiest way to do it.
If you're supporting 11+ then stick to android.app.Fragment
.
android.support.v4.app.Fragment
is the Fragment class 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.support.v4.app.Fragment
is a library that you can use to get backwards-compatibility for older API version.
android.app.Fragment
is the Fragment class in the native version of the Android SDK. It was introduced in 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
. If you're only targeting devices running API 11 or above, you can use android.app.Fragment
.
Android.app Fragments vs. android.support.v4.app using ViewPager?
You can use ViewPager
with native fragments from the android.app
package with the adapters from the android.support.v13.app package. You have to use the v13 support jar for that.
There are two versions of the adapters that work with ViewPager
, the ones in the v4
package are meant to be used with support fragments, the ones in v13
with native fragments.
The reason why there are now two fragment implementations is historical: Fragments in the android.app
package were introduced with Android 3 for tablets only and the support library was created to bring fragments to phones running older versions. On Android 4 you have both.
From my own experience I would recommend using support fragments, even when developing for Android 4. Here are some reasons: Fragment or Support Fragment?
Related Topics
How to Play Videos in Android from Assets Folder or Raw Folder
How to Add Apache Http API (Legacy) as Compile-Time Dependency to Build.Grade for Android M
How to Get the Height and Width of the Android Navigation Bar Programmatically
Android Fragment Onattach() Deprecated
Google Maps Android API V2 Authorization Failure
Reference One String from Another String in Strings.Xml
Android Popup Window Dismissal
Autocompletetextview Backed by Cursorloader
How to Show Dependencies Tree in Android Studio
Usage of Forcelayout(), Requestlayout() and Invalidate()
Error:(6, 0) Gradle Dsl Method Not Found: 'Google()'
Android Camera Preview Stretched
Android Arraylist of Custom Objects - Save to Sharedpreferences - Serializable
Determine Whether JSON Is a JSONobject or JSONarray
Android Locationclient Class Is Deprecated But Used in Documentation