0

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?

Mycoola
  • 1,135
  • 1
  • 8
  • 29
salezica
  • 74,081
  • 25
  • 105
  • 166
  • Here is answer from commonware onbActivity and AppCompatActivity. https://stackoverflow.com/a/31297546/1177865 – hjchin Aug 26 '18 at 04:31

2 Answers2

1

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.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
0

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.

enter image description here

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

hjchin
  • 864
  • 2
  • 8
  • 25
  • 1
    AppCompatActivity has nothing to do with ActionBar. Activity has an ActionBar as well. AppCompatActivity is a version of Activity that backports features to older platforms and provides bug fixes/behavioral normalization. – Gabe Sechan Aug 26 '18 at 04:10
  • I did missed out the SUPPORT version of ActionBar. If you look at the documentation, it is already the first line of the document. Thanks for pointing out my mistake. – hjchin Aug 26 '18 at 04:15
  • OP here. This answer does provide something useful: `AppCompatActivity` extends `Activity`. I don't understand the downvote, I'm upvoting – salezica Aug 26 '18 at 14:52