Search code examples
javaandroidandroid-fragmentactivityandroid-api-levels

FragmentActivity class for below api level 11 devices


I am new to android development.

I created class and extend that class from FragmentActivity.

When I use this function getFragmentManager()

it does not allow me to do it

I am also unable to use getSupportFragmentManager because its also giving me error that can not convert from support api to android.app

But then I used TargetApi(11) attribute on my abstract class that I extend from FragmentActivity class.

Now the error is gone.

But I like to know, does targetApi(11) limits my app from running my app on adroid devices below api 11?

Or below api 11 does not allow fragmment or hence does not support FragmentActivity class ?

If last thing that i mention is true, should I instead of fragment should I use new activities?


Solution

  • TargetApi(11) only suppress lint warning, you app can still run below 11. however if may crash if API is not available in lower Android platform.

    The correct way to solve your issue is use Android support library, it include FragmentActivity in package android.support.v4.app.

    You need edit you gradle file to include android support library

    dependencies {
        compile fileTree(dir: 'libs', include: '*.jar')
        compile 'com.android.support:support-v4:22.2.0'
    }
    

    Then sync gradle file and recompile your project.