Activity vs FragmentActivity?

I am new to Android. I want to create an application with a tab format. I found a lot of documentation where Activity was used. Also in many cases used FragmentActivity . I'm not sure where to start. Please suggest me to use Activity or FragmentActivity to start development in tab format?

+76
android android-activity android-fragmentactivity
Mar 10 '13 at 3:18
source share
3 answers

ianhanniballake is right. You can get all the functionality of an Activity from FragmentActivity . In fact, FragmentActivity has more functionality ).

Using FragmentActivity , you can easily create a tab and swap format. For each tab you can use different Fragment ( Fragments reuse). Therefore, for any FragmentActivity you can reuse the same Fragment .

However, you can use Activity for single pages, for example, enumerate something and edit the list item on the next page.

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

+107
Mar 10 '13 at 3:36
source share

FragmentActivity provides you with all the functions of Activity plus the ability to use Fragments , which are very useful in many cases, especially when working with ActionBar , which is the best way to use tabs in Android.

If you only use Honeycomb (v11) or higher device targeting, you can use Activity and use your own snippets introduced in v11 without any problems. FragmentActivity was created specifically as part of the Support Library to bring back some of these useful features (such as fragments) back to older devices.

I should also note that you will probably find Backward Compatibility - Implementing Tabs , very useful in the future.

+51
Mar 10 '13 at 3:28
source share

If you use the Eclipse New Android Project wizard in the recent ADT package, you will automatically get tabs implemented as fragments. This will greatly facilitate the conversion of your application to the tablet format in the future.

For simple single-screen layouts, you can use Activity .

+3
Mar 10 '13 at 3:28
source share



All Articles