Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Tools Getting Started with Android Studio Fragments and Layouts

Niranjan Deodhar
PLUS
Niranjan Deodhar
Courses Plus Student 1,941 Points

What is the difference between "extends Activity" and "extends ActionBarActivity"?

The project I have created has the former (in both API 14 and 19) but the tutorial has the latter....

3 Answers

Marcos Santiago
Marcos Santiago
1,573 Points

It's because Ben (the tutor) created a project with 'minSdkVersion 7' which is a version of Android that does not natively support the Action Bar which was introduced in Android 3.0 (SDK version 11).

You can read more about ActionBarActivity from the official documentation at http://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html

"Base class for activities that use the support library action bar features. You can add an ActionBar to your activity when running on API level 7 or higher by extending this class for your activity and setting the activity theme to Theme.AppCompat or a similar theme."

Could you clarify which project you're working on?

Niranjan Deodhar
Niranjan Deodhar
Courses Plus Student 1,941 Points

I doing the master detail lesson, since I posted the question I have seen the pattern that Eclipse creates ActionBarActivity but Android Studio creates Activity. Not that this answers my question - what is the difference between them?

Thanks and regards

ActionBarActivity is what's called an "indirect subclass" of the Activity class. Meaning that Eclipse is simply more specific than Android Studio in this case by extending the indirect subclass instead of the entire Activity class which includes it.