I've been building an app that untill recently had minSdkVersion="14"
, but i want to change that and add compatability for api 10. The first problem i had was with styles but i sort-off fixed it by using Theme.AppCompat
. Now i have problems in my code, the first one is that i'm using a lot of fragments.
The first fragments that appear in my app are:
FirstRunNotice firstRunNotice = new FirstRunNotice();
firstRunNotice.show(getFragmentManager(), "WhatDoesThisStringEvenDo?");
//.show method gives an error
This is just an inner class within my activity that extends DialogFragment
. How do i make this work on API 10? If i change it to android.support.v4.app.DialogFragment
it seems to take the errors away (using Android Studio) but it's weird because if i use it on one inner class (i have the DialogFragments) it takes the error away on both. Why is that?
Also, if i were to change all Fragment
extended classes to android.support.v4.app.Fragment, .DialogFragment, .ListFragment
... What would that do in case i run my app on a higher API, let's say 19? Would the app use the compatability library or would it know to use the class from that API? And is there a difference?
Since now you want to support Gingerbread and lower, you have to use the
android.support.v4.app.*
Fragment classes for your app to compile and run. The call togetFragmentManager()
should also be replaced withgetSupportFragmentManager()
It is also important to note that calling
getSupportFragmentManager()
is only part ofFragmentActivity
andActionBarActivity
(the latter is an extention of the former. It is a part of Google's ActionBarCompat library).This is because since the support Fragments are an addition to the Android system, there needs to be a way to implement them without relying too much on the Android internals (since Gingerbread and lower have no notion of a
Fragment
).It's likely you are encountering multiple Android Lint errors
Nothing, the support library works with new API versions as well. Of course, if you had previous code that required API 11+, then you need to figure out a way to backport that as well.
The support
Fragment
documentation says:Support Fragments will always be used. Usually, this isn't an issue.