Nested Fragments with v13 of the Android Support Library - android

I am trying to use nested fragments with the v13 Android support library and I am unable to call getParentFragment(). I have use the v4 support library with nested fragments and have successfully made calls to getParentFragment.
Does the v13 Android support library support nested fragments? Or, can you only use nested fragments with the v4 support library, or if the app targets API 17?

Do not use v13 unless you know it's fine for you:
This library is designed to be used for Android 3.2 (API level 13) and
higher. It adds support for the Fragment user interface pattern with
the (FragmentCompat) class and additional fragment support classes For
more information about fragments, see the Fragments developer guide.
For detailed information about the v13 Support Library APIs, see the
android.support.v13 package in the API reference.
Use v4 of support library

I had this same issue. it turned out that my child fragment extended Fragment. I changed it to extend android.support.v4.app.Fragment and it worked fine.

Related

Is it safe to use android.app.Fragment while using compatibility library

My new project is gonna be of API 14 min level. I'm going to use the compatibility library because it holds a lot of cool stuff. Wouldn't I bump into any compatibility issues if I use android.app.Fragment instead of android.support.v4.app.Fragment?
I don't want to use the later because I would like to use new (Honeycomb) animation framework to animate fragments transition (and to use FragmentManager from SDK), for instance. Just afraid it wouldn't work with some components from the compatibility lib where android.support.v4.app.Fragment must be used.
Wouldn't I bump into any compatibility issues if I use android.app.Fragment instead of android.support.v4.app.Fragment?
Not generally. Use the v13 version of the base library, not the v4 one, so that you can pick up v13 editions of classes like FragmentPagerAdapter, which will work with the native API Level 11+ edition of fragments.

Which fragment library should I import?

I am implementing fragments with a DrawerLayout. I have 2 options when I import Fragments
android.support.v4.app
android.app
Which one should I use ? I dont see any difference except it seems like the android.support.v4.app has no support for objectAnimator.
What do you suggest ?
Edit: I only plan on supporting API level 14 and higher...
It depends on whether you are using Support Library.
If you are using fragments below api level 11 then use android.support.v4.app. In this case you will extend FragmentActivity which is the base class of support based fragments.
If you are using fragments in api level 11 and above use android.app. In this case you will extend standard Activity.
Take a look at the below link and decide on what versions your app should run. Depending on that decide whether you need support library or not.
https://developer.android.com/about/dashboards/index.html
I only plan on supporting API level 14 and higher...
Then there is no need to use support library. Use
import android.app.Fragment
and extend standard Activity.
If you are using support libary for drawerlayout then you should use android.support.v4.app for fragments.
You can use open-source "AndroidX" Support Library nowadays.
You can start from here AndroidX

Where is getChildFragmentManager in support library v13?

Android support library v13 is supposed to provide support for newer APIs from Android 3.1. However, as far as I can tell there is no support for child fragments. Specifically, where is getChildFragmentManager()? The v13 support library relies on native fragments, which didn't add this method until API level 17. I have an app with minimum SDK level 14 so I should be able to use the v13 support library, but it seems I can't.
I don't want to go all the way back to the v4 support library and take on all it's weight. The v13 library is perfect otherwise.
If you want to use nested fragments within a native Fragment. use getFragmentManager().
If you want to use nested fragments within a support library Fragment, use getChildFragmentManager().
Just found this out by accident. It works. :)
Android support library v13 is supposed to provide support for newer APIs from Android 3.1
Not really.
However, as far as I can tell there is no support for child fragments
Correct. You cannot change existing classes from an external library in Java. android.app.Fragment already exists, therefore the library cannot add methods to Fragment.
I have an app with minimum SDK level 14 so I should be able to use the v13 support library, but it seems I can't.
You can simply not use nested fragments. Or, use the fragments backport.
I don't want to go all the way back to the v4 support library and take on all it's weight
android-support-v13.jar is larger than android-support-v4.jar.
If v13 included all of v4 then what is its purpose?
It adds some classes, like native-fragment implementations of FragmentPagerAdapter and FragmentStatePagerAdapter, that are not needed for apps who do not have native fragments, because their android:minSdkVersion is below 11.
the v13 library uses the native fragments and activities, not support fragment
android-support-v13.jar contains all of the android.support.v4 and all of the android.support.v13 classes from the SDK.
you should just use the v4 support library fragments. then you can use nested fragments w/ api 14. There is no real downside to doing so. They are already included in the v13 support library (it includes all of v4)

Android Using only ViewPager from Support Library

The new edition of my app has a minimum SDK of 14, so I thought that I could get rid of the support.v4 library that I've been using for the older version. However, it now looks like I might have to use ViewPager and thus am back to including the library.
So can I just use the ViewPager-related classes from the library and not have to use the other classes that are now native in V14, such as Fragment (and also not have to change Activity to FragmentActivity)?
I would assume that I can do this (only use ViewPager from the library) but wanted to check to make sure.
You may have to use v13 support libraries for some things. If what you want to use exists in both v4 and v13, use v13. v13 works with Fragments native to the higher APIs, while v4 only works with v4 fragments.
I just created a project that has only ViewPager and it's closest dependencies - without Fragments and without actionbar, which are supported natively as of api level 14.
https://github.com/kilaka/ViewPager-Independent
Enjoy :)

Does the Android ICS API have a native equivalent to ViewPager support lib?

I have searched a bit around for a pager for fragment , I develop on ICS API.
I know about ViewPager and all the support libs for earlier version but i don't get why I should use a support library consider the fact that I use the lastest version of the api and don't plan to support earlier version.
Do I have to write the "ViewPager" myself or is there something i didn't see in the api.
Does the Android ICS API have a native equivalent to ViewPager support lib?
No.
I know about ViewPager and all the support libs for earlier version but i don't get why I should use a support library consider the fact that I use the lastest version of the api and don't plan to support earlier version.
The Android Support package is not only for backports of newer APIs. It is also for other classes that, for whatever reason, are not being added to the SDK, such as ViewPager and its supporting classes.
Do I have to write the "ViewPager" myself or is there something i didn't see in the api.
You are welcome to write your own implementation of a view paging component. Savvy programmers would use the one in the Android Support package, since it is already written and (mostly) debugged.
UPDATE: Note that ViewPager works just fine with pages that are:
API Level 11+ native fragments
Android Support backported fragments
arbitrary Views
For the first case, you need the v13 version of the support JAR, which contains v13 versions of the FragmentPagerAdapter and FragmentStatePagerAdapter classes.

Categories

Resources