Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use "regular" Fragments when you have the Android Compatibility Package?

From what I have read and heard, the Android Compatibility Package Fragments have the same capabilities than the "regular" Honeycomb Fragments.

  • On one hand you have Fragments that work with devices from 1.6 to 4.0.
  • On the other hand you have Fragments that only work with devices from 3.1 to 4.0.

Google is apparently planning to maintain the compatibility package for a while.

What are the reasons that would make me choose the "regular" ones instead of the ACP ones?

The only reason I could find is the size. The ACP jar is 220ko, but it is not that much in my opinion.

Is that a matter of speed? Something else I could not think about?

like image 667
Jonas Schmid Avatar asked Dec 15 '11 17:12

Jonas Schmid


People also ask

What is the purpose of Android 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.

Is it better to use fragments or activities?

After using multiple fragments in a single activity, we can create a multi-screen UI. Fragment cannot be used without an Activity. While Using fragments in the project, the project structure will be good and we can handle it easily.

Why do we need fragments?

Fragments are Android's solution to creating reusable user interfaces. You can achieve some of the same things using activities and layouts (for example by using includes). However; fragments are wired in to the Android API, from HoneyComb, and up.

What is the purpose of using fragments in an activity?

Fragments introduce modularity and reusability into your activity's UI by allowing you to divide the UI into discrete chunks. Activities are an ideal place to put global elements around your app's user interface, such as a navigation drawer.


1 Answers

From what I have read and heard, the Android Compatibility Package Fragments have the same capabilities than the "regular" Honeycomb Fragments.

Generally, yes. Note that it is now call the Android support package, since it has stuff in it that does not qualify for "compatibility", such as ViewPager.

What are the reasons that would make me choose the "regular" ones instead of the ACP ones?

  • Size, as you mention

  • You have to inherit from FragmentActivity, which can cause problems with other code where you cannot inherit from FragmentActivity (e.g., Google Maps and MapActivity)

  • Some things in Android will assume OS-supplied fragments (e.g., ActionBar.TabListener), which in some cases can be worked around but perhaps not in others

There are probably other reasons as well, but those are ones that come to mind.

like image 89
CommonsWare Avatar answered Oct 03 '22 07:10

CommonsWare