Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Better to use FragmentActivity (or ActionBarActivity) or system Activity when targeting min API 14 (ICS)?

I'm making my app to have minimum Android version of 4.0 (ICS, API level 14).

First I guessed that I can get rid of using FragmentActivity as the base class for the activities, but it seems that some support library classes like FragmentStatePagerAdapter is not available on the system framework, and it needs the support Fragment instead of the system Fragment.

So I wonder if I should make my activities inherit from the system Activity, or stay using FragmentActivity (or ActionBarActivity when using appcompat library)?

like image 881
Randy Sugianto 'Yuku' Avatar asked Feb 02 '14 18:02

Randy Sugianto 'Yuku'


People also ask

Should I use activity or AppCompatActivity?

If you want the backported Material Design look, use AppCompatActivity. If not, but you want nested fragments, use FragmentActivity. If not, use Activity.

Which one is better fragment or activity?

Activities are an ideal place to put global elements around your app's user interface, such as a navigation drawer. Conversely, fragments are better suited to define and manage the UI of a single screen or portion of a screen.

Should you use AppCompatActivity?

For a minimum API level of 15,the use of AppCompatActivity is recommended. Activity is the base class of all other activities, which i assume you mean as Normal Activity.

Why do we extend AppCompatActivity?

AppCompatActivity enables many of the backwards compatibility features in a transparent manner. For example, implements Material Design views and features not available in 4.0. So, it's still a good practice to use it.


2 Answers

some support library classes like FragmentStatePagerAdapter is not available on the system framework, and it needs the support Fragment instead of the system Fragment.

That is incorrect. There are two versions of FragmentPagerAdapter and FragmentStatePagerAdapter. One set (v4) uses the backport, the other (v13) uses the native API Level 11 version of fragments.

I wonder if I should make my activities inherit from the system Activity

Yes, unless you need nested fragments. Those did not show up until API Level 17. If you need that capability, you will need to use the backport, until such time as your android:minSdkVersion is 17 or higher.

like image 195
CommonsWare Avatar answered Oct 01 '22 09:10

CommonsWare


If your min api level is 14 you can extend Activity. You use Fragment from support library below api level 11 in which case you need to extend FragmentActivity.

http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html

If you want action bar below 11 then you need to extend ActionBarActivity

http://developer.android.com/guide/topics/ui/actionbar.html

Note:

 ↳  android.app.Activity
                   ↳    android.support.v4.app.FragmentActivity
                       ↳    android.support.v7.app.ActionBarActivity
like image 45
Raghunandan Avatar answered Oct 01 '22 09:10

Raghunandan