简体   繁体   中英

Writing an Android library: use AppCompat?

When writing an Android library, should I use the AppCompat or Support variants provided by the support library?

For example, should a method take an Activity or an AppCompatActivity ? support.v4.Fragment or android.app.Fragment ?

In general you should use the AppCompat libraries wherever possible. The library provides backporting for some new features (whatever is practical), and fixes bugs in various version specific versions. For Activities and Fragments its particularly important, as Fragments at least had major differences between versions.

AppCompatActivity is the base class that support Support library ActionBar while Activity is actually the parent of AppCompatActivity. Depending on your purpose of library, if you have no intention of using the Support library ActionBar / Fragment related feature in your library, I would say, in general, the activity class is sufficient for your library.

在此处输入图片说明

android.app.Fragment has been deprecated now with API 28. So just go for the support Fragment version .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM