12

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.

Blo
  • 11,903
  • 5
  • 45
  • 99
Greg Ennis
  • 14,917
  • 2
  • 69
  • 74
  • 2
    Misconception about the v4 library: It's not meant to be only useful up to v12 or so, it is downwards compatible to v4. – zapl Feb 18 '14 at 23:41
  • What do you mean by 'weight'? The v13 library already contains all of the v4 library and if you are only using v14+ methods then a few word substitutions should be all you need. – ianhanniballake Feb 18 '14 at 23:41
  • I should not need to use it if I am setting min SDK level to 14. – Greg Ennis Feb 18 '14 at 23:42
  • If v13 included all of v4 then what is its purpose? Thats not right... the v13 library uses the native fragments and activities, not support fragment – Greg Ennis Feb 18 '14 at 23:43

3 Answers3

8

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. :)

midnightstar
  • 572
  • 5
  • 13
  • Agreed - I'm calling the v4 Fragment library on the method getChildFragmentManager() and it works. – Simon Aug 23 '15 at 13:41
  • 1
    I'm using nested fragments in a fragmentPagerAdapter. It's working fine! One caveat: I had to detach my nested fragment in its parent's onPause() method, otherwise the fragmentManager would try to insert the nested fragment into the view, but the view would not exist. – mcissel Sep 16 '15 at 22:23
  • Google just have forgotten to add getChildFragmentManager() to support library v13! – Behzad Bahmanyar Jan 12 '17 at 07:39
3

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 4
    Thanks for the clarifications, however this situation seems a total mess, worse than I thought. If I am using a support library then why would I need a FragmentPagerAdapter that takes native fragments? I should just use support fragments for everything. So I still dont see the purpose of the v13 support library. This is a mess. – Greg Ennis Feb 18 '14 at 23:51
  • @GregEnnis: "If I am using a support library then why would I need a FragmentPagerAdapter that takes native fragments?" -- not everybody needs nested fragments. Those that do not need nested fragments can use the native fragment implementation. *You* are the one who has decided *you* want to use nested fragments, and for that you need to use the backport a little longer. – CommonsWare Feb 18 '14 at 23:54
  • 1
    Well I still think using v13 with native fragments is more lightweight, and the way to go if you are targeting SDK 14, because proguard will optimize out all the support junk I don't need. So I just won't use nested fragments although I still stand by my claim that this is a mess. – Greg Ennis Feb 19 '14 at 00:44
  • 10
    This is an absolute mess indeed. And @CommonsWare, you answers don't show your wisdom nearly as much as they do your arrogance. If you AREN'T using nested fragments then you're designing a UX experience of limited Android from years ago (which was already years behind the iOS CocoaTouch architecture). You SHOULD be using nested fragments and adopting their benefits, and trying to catch up to modern UIs instead of being bound by Android's ages-old (mis)architecture. Google dropped the ball yet again on not making child fragments properly compatible with the v13 support library. – Marchy Apr 01 '14 at 23:58
  • 2
    @Marchy: "If you AREN'T using nested fragments then you're designing a UX experience of limited Android from years ago" -- no, you just aren't using nested fragments. There is nothing that a fragment can do that cannot be solved without fragments. You could not have a backport of fragments as a library unless it were completely implemented as SDK-capable source code. Whatever that library can do, we can do, using our own source code. By extension, there is nothing that you can do with nested fragments that cannot be solved by other means. – CommonsWare Apr 02 '14 at 06:44
  • I agree with Marchy. CommonsWare wrote "There is nothing that a fragment can do that cannot be solved without fragments." My answer to you: Why fragments then? If Google introduces something, it should be good and solid. Otherwise it is a mess we are experiencing. – Yar Aug 13 '14 at 08:41
0

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)

dabluck
  • 1,641
  • 2
  • 13
  • 20
  • v13 doesnt include getChildFragment! – Jono Nov 04 '14 at 15:35
  • it certainly does. http://developer.android.com/reference/android/support/v4/app/Fragment.html#getChildFragmentManager – dabluck Nov 04 '14 at 17:36
  • Doesnt. need v4 to access that method apparantly – Jono Nov 05 '14 at 10:43
  • v4 is in v13. v13 is a superset of v4. so if it's in v4, it's in v13 my friend. like i said in the original post you're commenting on. what are you confused about? – dabluck Nov 05 '14 at 19:33
  • What I mean is that v13 activity doesn't have get child fragment method and u can try use it for Standard fragments – Jono Nov 09 '14 at 09:40