5

I am following an Android lesson and under the Support Android 2.1 and Above section it is said my Activity should extend the ActionBarActivity class to support Action Bar on API-7 onwards.

However, documentation also says that this class is deprecated and I should use AppCompatActivity instead. I'm confused here, which one should I use and why?

Not Gabriel
  • 531
  • 4
  • 13

2 Answers2

13

Yes. You should use AppCompatActivity.

The AppCompatActivity is a very new class and the training section on the android website is outdated.

Everything that you would do with ActionBarActivity will work mostly the same on AppCompatActivity.

For differences please read the post about it http://android-developers.blogspot.de/2015/04/android-support-library-221.html

Budius
  • 39,391
  • 16
  • 102
  • 144
  • Thanks. While you're at it, how can I check which version of the library is the latest? I had this doubt when adding the `compile 'com.android.support:appcompat-v7:22.1.+'` line. Documentation says 20.something.something. – Not Gabriel May 26 '15 at 15:50
  • At the moment I don't of any place you can check what's the latest. What I usually do is write `compile 'com.android.support:appcompat-v7:+` and then await for Gradle warning telling me which one is the latest and then change to it. – Budius May 26 '15 at 15:53
  • @NotGabriel when you open your Gradle scripts in Studio, it will use a Lint check to tell you which versions of the Google libraries (at least) are outdated. This can be configured (severity level) and de/activated at Settings→Editor→Inspections, and under “Android Lint” look at “Obsolete Gradle Dependency”. It will then highlight all lines for libraries which have a newer version. Additionally, for other libraries, you can check the library name in sites like Gradle, please: http://gradleplease.appspot.com/ – davidcesarino May 26 '15 at 16:08
  • @DavidCesarino That's interesting, thanks for the link, it will definitely come in handy. – Not Gabriel May 26 '15 at 16:21
0

My understanding is that you need to use AppCompatActivity. If the other support libraries or classes are now deprecated, that means that the folks at Android aren't going to be maintaining that code or improving it anymore. I've never actually used either of those classes though.

I suppose you could have some ugly if statements to check the API level of your end users and based on that make different method calls. That sounds like a lot of extra work though.

Chamatake-san
  • 551
  • 3
  • 10