1. Are you ready for the Galaxy S20? Here is everything we know so far!

Avtivity vs AppCompatActivity

Discussion in 'Android Development' started by Bee Torika, Feb 27, 2016.

  1. Bee Torika

    Bee Torika Newbie
    Thread Starter


    I just start to use AppCompatActivity, because when I create new project by selecting blank activity template,
    android studio create class file extends AppCompatActivity.

    I know it is from android.support.v7.app.AppCompatActivity.

    But, is that much better than Activity ?

    And almost all android devices can import this class (AppCompatActivity) ?
    (I mean, is this safe to use that class ? I dont want my app couldnt be run in old android device, because my app uses that class.)

    What is main difference between Activity and AppCompatActivity ?


  2. Best Answer:
    Post #2 by Deleted User, Feb 27, 2016 (1 points)

    1. Download the Forums for Android™ app!


  3. Deleted User

    Deleted User Guest

    This might be of some interest. From http://stackoverflow.com/questions/...mentactivity-and-actionbaractivity-when-to-us

    Activity is the baseline. Every activity inherits from Activity, directly or indirectly.

    FragmentActivity is for use with the backport of fragments found in the support-v4 and support-v13 libraries. The native implementation of fragments was added in API Level 11, which is higher than your proposed minSdkVersion values. The only reason why you would need to consider FragmentActivity specifically is if you want to use nested fragments (a fragment holding another fragment), as that was not supported in native fragments until API Level 17.

    AppCompatActivity is from the appcompat-v7 library. Principally, this offers a backport of the action bar. Since the native action bar was added in API Level 11, you do not need AppCompatActivity for that. However, current versions of appcompat-v7 also add a limited backport of the Material Design aesthetic, in terms of the action bar and various widgets. There are pros and cons of using appcompat-v7, well beyond the scope of this specific Stack Overflow answer.

    ActionBarActivity is the old name of the base activity from appcompat-v7. For various reasons, they wanted to change the name. Unless some third-party library you are using insists upon an ActionBarActivity, you should prefer AppCompatActivity over ActionBarActivity.

    So, given your minSdkVersion in the 15-16 range:

    • If you want the backported Material Design look, use AppCompatActivity

    • If not, but you want nested fragments, use FragmentActivity

    • If not, use Activity
    Bee Torika and scary alien like this.
  4. Bee Torika

    Bee Torika Newbie
    Thread Starter

    LV426 !
    Thank you so much ^ ^
    have a nice weekend

Share This Page