Why are there two Fragment classes in Android? [duplicate]

孤街醉人 提交于 2019-12-11 17:17:59

问题


In a recent question, the OP received an unexpected error message due to importing Fragment from the android.app package. The solution to fix the error was to import android.support.v4.app.Fragment instead. Why are there two different Fragment classes that appear to have the same functionality?


回答1:


According to the documentation, fragments were introduced in Android 3.0 (API 11). Around the same time, Google also released the Android Support Library which allowed developers to use fragments and other new APIs on devices that ran older versions of Android. This library contained classes with the exact same functionality as classes that shipped with the Android API on newer devices. Since these libraries can be compiled directly into your APK file, you no longer have to rely on the features being available on the target device. Some classes are now only available from the Support Library and rely on the support Fragment from this library rather than using the native Fragment class even though it is available on basically all devices now in use.



来源:https://stackoverflow.com/questions/48291270/why-are-there-two-fragment-classes-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!