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?

- 970
- 1
- 7
- 8
3 Answers
ianhanniballake is right. You can get all the functionality of Activity
from FragmentActivity
. In fact, FragmentActivity
has more functionality.
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.

- 2,777
- 2
- 15
- 25

- 4,210
- 8
- 35
- 46
-
FYI, I found some good discussions about Fragment Android in another language here [Fragment trong Android](http://www.umbalaaz.com/threads/cach-su-dung-fragment-trong-android.336/) – UmbalaAZ May 11 '15 at 02:45
-
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). – ToolmakerSteve Sep 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 Vork Jun 23 '16 at 09: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.
I should also note that you'll probably find the Backward Compatibility - Implementing Tabs training very helpful going forward.

- 191,609
- 30
- 470
- 443
-
3@A--C - I've edited my answer - you are correct that API 11+ devices can use native Fragments and the normal Activity class. – ianhanniballake Mar 10 '13 at 03:36
-
I'm going to challenge the assertion that the normal Activity class can be used as a Fragment in API11+. This appears to have changed in KitKat. See https://android.googlesource.com/platform/frameworks/base.git/+/kitkat-mr1-release/core/java/android/app/Fragment.java#584 – cmarcelk Oct 28 '14 at 18:03
-
1@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. – ianhanniballake Oct 28 '14 at 18:10
-
@cmarcelk in API11+ `Activity` can *access* fragments; `FragmentActivity` is no longer required. Activity or FragmentActivity are not themselves Fragments. – ToolmakerSteve Sep 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.
For simple single screen layouts you may still use Activity
.

- 23,228
- 4
- 34
- 43