This site uses cookies to deliver our services and to show you relevant ads and job listings.
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.
Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these policies and terms.

Join us in building a kind, collaborative learning community via our updated
Code of Conduct.

I am new in Android. I want to build an app with tab format. I found many documentation where Activity has been used. Also in many cases have used FragmentActivity. I am not sure which will be better to start. Please suggest me should I use Activity or FragmentActivity to start development in tab format?

3 Answers
3

Using FragmentActivity you can easily build tab and swap format. For each tab you can use different Fragment (Fragments are reusable). So for any FragmentActivity you can reuse the same Fragment.

Still you can use Activity for single pages like list down something and edit element of the list in next page.

Also remember to use Activity if you are using android.app.Fragment; use FragmentActivity if you are using android.support.v4.app.Fragment. Never attach a android.support.v4.app.Fragment to an android.app.Activity, as this will cause an exception to be thrown.

BUT see @ianhanniballake's answer: unless targeting API's older than API 11, you can use Activity instead of FragmentActivity, and still have access to Fragments; this answer doesn't quite say that (though the last paragraph implies that).
– ToolmakerSteveSep 21 '15 at 12:29

As we know, mostly we have a BaseActivity in our project, and all the other activities will extend it.But when comes to FragmentActivity, we can't do it. So I don't use FragmentActivity even in the case of tab.
– Allen VorkJun 23 '16 at 9:00

FragmentActivity gives you all of the functionality of Activity plus the ability to use Fragments which are very useful in many cases, particularly when working with the ActionBar, which is the best way to use Tabs in Android.

If you are only targeting Honeycomb (v11) or greater devices, then you can use Activity and use the native Fragments introduced in v11 without issue. FragmentActivity was built specifically as part of the Support Library to back port some of those useful features (such as Fragments) back to older devices.

@cmarcelk - not sure what 'the normal Activity class can be used as a Fragment' means - I said that android.app.Activity works with android.app.Fragment, not anything about them being interchangeable.
– ianhanniballakeOct 28 '14 at 18:10

@cmarcelk in API11+ Activity can access fragments; FragmentActivity is no longer required. Activity or FragmentActivity are not themselves Fragments.
– ToolmakerSteveSep 21 '15 at 12:27

If you use the Eclipse "New Android Project" wizard in a recent ADT bundle, you'll automatically get tabs implemented as a Fragments. This makes the conversion of your application to the tablet format much easier in the future.