Android snippets: Support library crashes when extending Activity class
I am researching android development right now and I came across a fragment class.
I found out here that we can use two imports for the fragment class, namely
- android.support.v4.app.Fragment : Can be used for API <11 as well.
- android.app.Fragment : only used for API> = 11.
However, I found that when I use the support snippet in an Activity , it crashes when I extend the Activity class . The Support Fragment works great when I extend the FragmentActivity or ActionbarActivity.
Please help me understand why this is happening.
source to share
You need to choose whether you are using classes from the support library or not. If you do this, you must use classes that are compatible with each other. FragmentActivity
and ActionBarActivity
are part of the support library, so they support android.support.v4.app.Fragment
. Activity
not from lib support, so it does support android.app.Fragment
.
In principle, Activity
they ActionBarActivity
do the same. There are minor differences between the 2, the main one being the method getFragmentManager()
in Activity
which is replaced with getSupportFragmentManager()
in the support library. Other methods that differ are usually prefixed with "support" in the ActionBarActivity
.
source to share