Understanding Android Support Library

Source: Internet
Author: User

One of the great things about the Android platform is that it supports a variety of different devices. From your tablet to your phone, TV, etc., Android is everywhere. Android wants to be a full-field mobile computing platform. The light has been very successful in its number.

There are some challenges in supporting all of these devices. Regardless of hardware or software, the user wants the application to run on every device, and again, for developers, you can't always expect users to upgrade to the latest Android version. In fact, most users encounter a user who uses a version 18 months ago or older.

Without the help of the Android team, developers would have to do "ugly code" to be compatible with users who use older versions. Fortunately, the Android team is aware of the importance of embracing older devices. But being compatible with the old without compromising the new requirements is an architectural challenge because the Android interface has been changing with the version evolution. How do you get those old Android devices that haven't updated their devices to run these latest Android interfaces successfully?

The answer is the most important and bizarre design decisions the Android team has made: the Android support Library

What is an Android support library ?

As early as 2011, it was released as an Android-compatible library, used in 75% of applications, and is the most widely used ANDROCU. It is actually not a single file, but rather a collection, which can be broadly divided into two groups: compatible libraries and component libraries .

Each library indicates the minimum supported SDK version. It is easy to be mistaken that a high-version support library is easily understood to cover all the content of the lower-version support library. In fact, this is not the case. (Maybe you think V7-appcompat contains V4, but that's not the case)

Compatibility library (Compatibility Lib)

Focus on the new version backwards compatible so that the old version can use the new API. The main compatibility libraries are available in V4 and V7 versions.

V4

As the name implies, it is backwards compatible to API4. Support for implementations of major classes, such as frament and loader (API11 introduction), and support for widely used but nonexistent classes in the framework, such as Viewpager and Drawerlayout.

Don't look at your name. Whether or not to support Android 1.6, there are still some useful and important libraries. And because of the support library reference dependency, it is generally difficult to avoid v4.

V7

Usually used purely for compatibility. V7 provides such as Actionbar (API11 introduction), Toolbar (API21 Introduction), and backwards compatibility to API7. It relies on the V4 support library.

Backstage situation

The Compatibility Library uses shims technology ( shims ) to support back-up in large numbers. These shrims are simple encapsulation, and if called on the new version, Shrims will call into the underlying framework implementation; In older versions, it might be a slightly different implementation or some functionality reduced.

In some cases, shim is not used. In contrast, the support library uses a set of its own implementations instead of the framework implementations. (May really not be 100% compatible) The main example is the fragment in V4. This fragment is not the same as the fragment in the framework, nor is it compatible.

This affects the entire Android framework, and this is an interesting design. Android creates a whole set of different compatible implementations that repeatedly create a lot of the same functionality. These backward-compatible implementations are parallel to the framework and have their own inheritance structures as well as bugs.

Google claims that most of the APIs are still the same in these cases, except those that belong to different package and have some different methods. In fact, there are some inconsistencies and non-significant differences between the supporting libraries and the framework, and these differences are likely to grow over time.

also, in some cases, developers assume that they have a choice to use the framework or support library, but this has to be obeyed by where the supported references come from. For example, the V7 Support library allows developers to use the material Design UI (API 21 introduction). But this requires activity to inherit appcompatactivity, whereas Appcompatactivity is inherited from Fragmentactivity (v4). So under API21 or using the material Design UI feature, all of the V4 versions of fragment are enforced instead of fragment in the framework. But Google believes that using a support library is a good practice, even if there is no need to use it.

Component Library

The Android Support Library also provides a smaller, more modular library of components, allowing developers to add features that are not in the framework. These libraries can be easily deleted without having to consider reference issues. Here are a few of the valuable component libraries:

    • V7-recyclerview: Provides the Recyclerview component, which efficiently displays and animates large amounts of DA Ta and is designed to replace ListView
    • V7-cardview: Provides the CardView component, enabling the cards UI design pattern
    • v7-gridlayout: Provides the GridLayout class, which enables organizing UI elements into a rectangular grid
    • v7-mediarouter: Provides Mediarouter and related classes, enabling Google Cast support
    • V7-palette: Provides the palette class, which enables developers to identify primary colors in an image

Adding these components to your project is as simple as adding a reference to your build script.

Not to mention the benefits of convenience and modularity, pulling components out of the library allows Google to publish important APIs outside the framework. This facilitates the collection of feedback and design iteration updates before formally entering the framework. It's better to make changes than to publish in the framework first.

Other libraries

It also contains some other less-used libraries, but it is worth noting that:

    • V8: provides support for Renderscript (introduced in API one) back to API 8
    • V13: Provides additional compatibility support for the Fragment UI pattern and bundles the V4 Library
    • v17: Provides support for building TV UIs
    • Multidex: Provides support for building apps with multiple DEX files
    • Annotations: Provides support for annotations like @NonNull and @IntDef
FAQs When should I use the Android support library?

If you need a feature that is older than the minimum SDK version that your app supports, or that feature is not supported in the standard framework.

But Google believes that using a support library is a good practice, even if there is no need to use it.

Which version should I use?

In short, use a version that has the functionality you need. For example, if you want to use Recyclerview, simply add the V7-recycleview reference to your build script.

If you need a V4 component, you can use V13 if your minimum SDK version is supported.

However, supporting references in the library may make you decide which version to use.

Translated from http://martiancraft.com/blog/2015/06/android-support-library/

Understanding Android Support Library

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.