Reputation: 132
I am learning android development right now and i came across the fragment class.
Here I found out that we can use two imports for the Fragment Class, namely
However I found that when I use support fragment in an activity, it crashes when I extend the Activity class. The Support Fragment works fine when I extend FragmentActivity or ActionbarActivity.
Please help me understand why does this happen.
Upvotes: 3
Views: 277
Reputation: 8629
You have to choose whether you use classes from the support library or not. If you do, you have to use classes that are compatible with each other. FragmentActivity
and ActionBarActivity
are part of the support library, hence they support android.support.v4.app.Fragment
. Activity
is not from the support lib, so it supports android.app.Fragment
.
Basically, Activity
and ActionBarActivity
do the same things. There are minor differences between the 2, the main one being the method getFragmentManager()
in Activity
being replaced by getSupportFragmentManager()
in the support library. Other methods that differ are usually prefixed with 'support' in ActionBarActivity
.
Upvotes: 2