Which Activity should we use?

android

There are four different activities:

1- android.app.Activity

Every activity inherits from this one.

This class doesn’t support fragment until API level 11.

This class doesn’t support nested fragments until API level 17.

2- android.support.v4.app.FragmentActivity

This class is from appcompact-v4 library.

Features:

  • Supporting nested fragments
  • Loader

To use this class you should add below dependency to gradle.build

compile 'com.android.support:appcompat-v4:x.x.x'

3- android.support.v7.app.AppCompatActivity

This class is from appcompact-v7 library.

Features:

  • Supporting all v4 features
  • Material Design

To use this class you should add below dependency to gradle.build

compile 'com.android.support:appcompat-v7:x.x.x'

4- android.support.v7.app.ActionBarActivity

This class is the old name of AppCompatActivity. For various reasons they changed the name.

Conclusion

  • If you want support Material Design look and fragment under API level 21 you should use AppCompatActivity
  • If you want support nested fragments under API level 17 you should use FragmentActivity
  • If you want support fragment under API level 11 you should use FragmenActivity
  • Else use Activity

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s