Ashhar Jawaid
Ashhar Jawaid

Reputation: 132

Android Fragments : support library crashes on extending Activity class

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

  1. android.support.v4.app.Fragment : Can be used for API < 11 as well.
  2. android.app.Fragment : Used for API >= 11 ONLY.

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

Answers (1)

2Dee
2Dee

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

Related Questions