Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Android dashboards show that only half of devices have Android 5.0 and above, but numbers look different for our customer data set - it's over 93% of our users. So we've decided to abandon support for devices with Android version lower than 5.0 and change minSdkVersion from 15 to 21.

This upgrade require from us to review all of obsolete functionalities and clean some hacky workarounds which we applied to support older versions. One of main functionality which we can apply now is to replace android.support.v4.app.Fragment with android.app.Fragment. It sounds like good idea, especially when we know that fragment API had been reviewed and improved.

Just to make sure that I’ll take right path and android.app.fragment won’t surprise me I would like to paraphrase question from this stackoverflow thread - Are you using fragments from the support library, even though they are already available, when developing for Android 5? Are there any bugs in fragment API which occur on Android 5.0 and above and were fixed in support library?

Update

After Android-KTX release, Jake Wharton made the following statement in one of PRs:

Thanks for taking the time to make the PR (with tests!), but we would like to encourage that developers only use the support library fragments. The next version of Android will deprecate the version of fragments that are part of the platform. Thus, we aren't going to add any extensions to support them in this project.

So using fragment from support library is the right thing to do.

like image 996
Krzysztof Skrzynecki Avatar asked Jan 11 '17 14:01

Krzysztof Skrzynecki


1 Answers

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.

like image 178
Gabe Sechan Avatar answered Nov 16 '22 01:11

Gabe Sechan