Fragment or Support Fragment

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.

Fragment or Support Fragment?

From my experience, using the same fragment implementation on all Android devices is a great advantage. I could not get rid of all NullPointerExceptions when state is saved on Android 4.0 using native fragments, with the support library they are all gone. Also I could not see any disadvantage so far with this approach.

So my answer to my own question is now: When developing for Android 4.x, using the fragments from the support library is a good idea. The support library has bugs fixed that are still present in older fragment implementations and is frequently updated with more bug fixes.

Support fragment vs Native fragment

This should help you decide as it's now the official Android Team stance:

Fragment

This class was deprecated in API level P.

Use the Support Library Fragment for consistent behavior across all devices and access to Lifecycle.

Source: https://developer.android.com/reference/android/app/Fragment

But are these benefit enough [...]?

Absolutely, you want the consistent behavior without having to cater to each API level and vendor specific quirks.

Fragment vs Support Fragment when targeting api 21 (Android 5.0) and above

I would suggest using the support library fragments anyway, for a few reasons:

  1. Future features may be added and backported, and then you'd need to rewrite to use them
  2. Consistency. The support library works to make sure support fragments always work the same. Whereas the native fragments may have subtle differences between versions.
  3. The support library can contain bug fixes to the platform and can be updated much more frequently.

Edit: As of 2018, the OS level Fragment is deprecated. Google's path forward technically is to do less in the OS library and more in add ons. So for Fragment this is absolutely now support library, and likely to go this way for more items.

Difference between Fragment Manager and Support Fragment Manager

The concept of Fragments came only after API 11...in order to support those functions in older API version we use Support Libs... I think you have completely mis understood the concept of using support libs.. Do have a look into this question and a quick Google will help u out

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.

Type Mismatched on Fragment

your QRCodeFragment class is extending Fragment, which? (check imports on top of a file)

we have android.app.Fragment and androidx.fragment.app.Fragment - pick proper needed by your method

built-in android.app.Fragment is currently deprecated, you should use androidx version, but there is a chance that some libraries still needs original one (sadly)



Related Topics



Leave a reply



Submit