I want to use Fragments in my application, but I cannot extend FragmentActivity because my application already extends an activity that is part of a library. Since this means that I cannot call getSupportFragmentManager()
, I am looking for a workaround that would allow me to use Fragments without having to extend FragmentActivity. Is it possible?
Asked
Active
Viewed 6,547 times
6

JohnEye
- 6,436
- 4
- 41
- 67
-
1This is unfortunately not possible. Is the library of yours or open source? You might change the Activity you extend and make it extend FragmentActivity instead of Activity – Benoît Bouré Oct 03 '12 at 13:47
-
Are you sure? I read somewhere that it could be possible using some Interface magic. The library is indeed open source, but I wanted to avoid changing it so as to keep being able to update it from the repository. – JohnEye Oct 03 '12 at 13:56
-
1Not sure how it could be done properly without extending FragmentActivity. Have you considered asking the library developer for Fragment Support? – Benoît Bouré Oct 03 '12 at 14:06
-
Wouldn't that make the support package mandatory for everyone? – JohnEye Oct 03 '12 at 14:14
-
1Good point. I don't know what library you are using. It could have a CustomActivity and a customFragmetnActivity... Don't know... – Benoît Bouré Oct 03 '12 at 14:19
1 Answers
2
Your library is going to need to extend the FragmentActivity
.
I would be concerned about a library that requires you to use their base activities anyway.
As mentioned (where possible) grab the library source code and add it as a library project to eclipse and make its activities extend the FragmentActivity
class.

Chris.Jenkins
- 13,051
- 4
- 60
- 61
-
the youtube player api for android is such a library. it requires you to inherit from YouTubeBaseActivity. – kritzikratzi Apr 04 '14 at 17:47
-
@kritzikratzi Youtube api might have a `YouTubeSupportBaseActivity`. It's bad design inheriting, should always compose. Raise a bug on b.google.com – Chris.Jenkins Apr 08 '14 at 16:48
-
there is no such thing as YouTubeSupportBaseActivity. there is also no such thing as b.google.com – kritzikratzi Apr 09 '14 at 20:44