I have used it in my basic code replace activity by fragment activity,but i have not got any kind of error.Application has working.
As seen in the documentation:
FragmentActivity
Base class for activities that want to use the support-based Fragment
and Loader APIs.
Activity
An activity is a single, focused thing that the user can do. Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with setContentView(View). While activities are often presented to the user as full-screen windows, they can also be used in other ways: as floating windows (via a theme with windowIsFloating set) or embedded inside of another activity (using ActivityGroup)
Can see more at : http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html
A fragment activity can contain fragments (as it's name implies). It's the support version of activities for older APIs, which want to use fragments.
A Fragment , introduced in Android 3.0 HoneyComb is a portion of a user interface inside an activity. You can have many fragments in you UI.
FragmentActivity is the base class you must extend in order to use fragments with the support library.
The nuance here is that an Activity can use Fragments from the native SDK (as long as you are targeting API 11+), while a FragmentActivity can use Fragments from the support library.
So, assuming API 11+, if you are using android.app.Fragments in your app, you can use Activity, but if you are using android.support.v4.app.Fragments in your app, then you must use FragmentActivity.
Related
I came across this article but this article suggests replacing the FragmentActivity's code with that of the old Activity code. I can do that but would like to know if there's a way to just create Activity instead. I updated to ADT v22.6 today. Could that be the problem?
Another problem is that this requires a min-SDK of 7 while right now I want a min-SDK of 3.
Also, I am using Eclipse and not Android Studio.
Thanks in advance!
The new ADT 22.6 has new feature added that it will automatically create the any new activity as FragmentActivity not an single activity. So if you wish to create an Activity you can create it by explicitly creating separate class and extends Activity.
I'm afraid that google is enforcing us to use fragments activities instead of plain activities now. You either can go back to an SDK previous to 22.6 or just create the activities by just extending the class, adding a layout and adding the activity reference to the manifest.
I'm trying to pass data from tab n to tab n+1 activities, based on TabActivity in the MainContainerActivity, using parcelables but can't succeed as I can not apply "getExtras" method on the tab n+1 intent.
I can pass my parcelable object from one tab to the next one if I start the tab n+1 activity using startActivity(nextactivity) instead of using the tab switcher with tab.setCurrentTab(tab_n+1).
How shall I manage the activity intents sothat I can succeed to pass those parcelable objects, still implementing TabActivity in the MainContainer class and Activity in the tabs ?
or is there a way to force the activity start in the manifest when using tab.setCurrentTab(tab_n+1) ?
I read dozen of threads and have been trying many misc tests but w/o success so pls detail the answer as for a real noob :-)
EDIT:
Looking to get this working from API8 onwards
As explained here :
Restarting an activity in a single tab in a TabActivity?
What you want is to destroy the activity and start it again, by passing the new Parcelable "arguments" in the intent.
The suggested method will probably work, however I strongly suggest you to consider using Fragments instead. If you want to support version prior Android 3, you will need the support package.
The examples listed in this thread: https://stackoverflow.com/questions/5710573/need-a-fragments-example should get you started on Fragments.
I guess the simple answer to my simple 3 tabs application is using a global object as described here, which also allow keeping my existing source code.
My question is apart from the obvious inheritance differences, what are the main differences between Fragment and FragmentActivity? To what scenarios are each class best suited? I'm trying to get an understanding of why both of these classes exist...
A Fragment is a section of an Activity, which has:
its own lifecycle
receives its own input events
can be added or removed while the Activity is running.
A Fragment must always be embedded in an Activity.
Fragments are not part of the API prior to HoneyComb (3.0). If you want to use Fragments in an app targeting a platform version prior to HoneyComb, you need to add the Support Package to your project and use the FragmentActivity to hold your Fragments. The FragmentActivity class has an API for dealing with Fragments, whereas the Activity class, prior to HoneyComb, doesn't.
If your project is targeting HoneyComb or newer only, you should use Activity and not FragmentActivity to hold your Fragments.
Some details:
Use android.app.Fragment with Activity. Use android.support.v4.app.Fragment with FragmentActivity. Don't add the support package Fragment to an Activity as it will cause an Exception to be thrown.
A thing to be careful with: FragmentManager and LoaderManager have separate support versions for FragmentActivity:
If you are using a Fragment in an Activity (HoneyComb and up), call
getFragmentManager() to get android.app.FragmentManager
getLoaderManager() to get android.app.LoaderManager
if you are using a Fragment in a FragmentActivity (pre-HoneyComb), call:
getSupportFragmentManager() to get android.support.v4.app.FragmentManager.
getSupportLoaderManager() to get android.support.v4.app.LoaderManager
so, don't do
//don't do this
myFragmentActivity.getLoaderManager();
//instead do this:
myFragmentActivity.getSupportLoaderManager();
or
//don't do this:
android.app.FragmentManager fm = myFragmentActivity.getSupportFragmentManager();
//instead do this:
android.support.v4.app.FragmentManager fm = myFragmentActivity.getSupportFragmentManager()
Also useful to know is that while a fragment has to be embedded in an Activity it doesn't have to be part of the Activity layout. It can be used as an invisible worker for the activity, with no UI of its own.
FragmentActivity is our classic Activity with fragment support, nothing more. Therefore FragmentActivity is needed, when a Fragment will be attached to Activity.
Well Fragment is good component that copy the basic behaviors of Activity, still not a stand-alone application component like Activity and needs to be attached to Activity in order to work.
Look here for more details
Think of FragmentActivity as a regular Activity class that can support Fragments. Prior to honeycomb, an activity class could not supoprt Fragments directly, so this is needed in activities that use Fragments.
If your target distribution is Honeycomb and beyond you can extend off of Activity instead.
Also a fragment is to be considered as a 'sub-activity'. It cannot exist without an activity. Always think of a fragment as a sub-activity and you should be good. So the activity would be the parent and the fragment(s) the child kind of symbolic relationship.
a FragmentActivity is an ad-hoc activity that contains Fragment.
In these few words I have explain you one of the main important changes that, with android 3.0(HoneyComb), android team has inserted in the android sdk.
With these new kind of concept your pieces of code and layout becomes more flexible and maintainable. If you search on google there are a lot of examples.
I was working on fragments and came across two things Activity and FragmentActivity which are used several times. I want to know that is there any difference between these two, because when I changed Activity with FragmentActivity, it had no effect on the app.
A FragmentActivity is a subclass of Activity that was built for the Android Support Package.
The FragmentActivity class adds a couple new methods to ensure compatibility with older versions of Android, but other than that, there really isn't much of a difference between the two. Just make sure you change all calls to getLoaderManager() and getFragmentManager() to getSupportLoaderManager() and getSupportFragmentManager() respectively.
FragmentActivity is part of the support library, while Activity is the framework's default class. They are functionally equivalent.
You should always use FragmentActivity and android.support.v4.app.Fragment instead of the platform default Activity and android.app.Fragment classes. Using the platform defaults mean that you are relying on whatever implementation of fragments is used in the device you are running on. These are often multiple years old, and contain bugs that have since been fixed in the support library.
I have created tabs using intents.MainPage.java is my class that extends TabActivity and other 5 activites that extends Activity which i have added as tabs. I need to get Strings from the 5 activities which i have added as tabs once a click is performed in the MainPage.java class
From the documentation:
The TabActivity class is deprecated. New applications should use
Fragments instead of this class; to continue to run on older devices,
you can use the v4 support library which provides a version of the
Fragment API that is compatible down to DONUT.
Here are some Fragment tutorials to help you get started.
Also, check out FragmentTabs.java on the developer site.