Reputation: 740
I am referring the big nerd ranch android book to learn android.
When I reached chapter 7 which starts explaining fragments, It said that if I wanted my app to support devices with API < 11, I needed to use Fragments of android.support.v4 library and have my classes extend FragmentActivity. But I decided to use Fragment in the default library and have my classes extend Activity... hope you get what I mean to say.
Then I reached chapter 13 which explains toolbar, it said that toolbar was introduced in Android 5.0, so here I decided to use the AppCompat library and have my classes extend AppCompatActivity (which ultimately extends FragmentActivity).
When I extended my classes with AppCompatActivity, I immediately got errors like: cannot resolve method getActivity(), setArguments(), getArguments()
So does that mean I have to use android.support.v4.library Fragment if I use AppCompat?? Since I am a beginner, I have a few more questions...
I don't think I'll ever have my apps support API < 16... so is this approach (use android.support.v4.library Fragment if I use AppCompat) recommended for long term use... or large projects? Or is there a better way, or a workaround?
Upvotes: 0
Views: 1026
Reputation: 157437
So does that mean I have to use android.support.v4.library Fragment if I use AppCompat??
No you don't. You can still use the native fragment support even though you are extending AppCompatActivity
. You will use getFragmentManager()
instead of getSupportFragmentManager()
. Still I strongly recommend that you use the support library support. With every update of the support library you get bugfixing and potentially new functionality, mostly available also on old versions of Android, that you otherwise can't use
Upvotes: 2