I have to write an app for both phones and tablets and I would like to use the same project for both. It seems the use of compatibility library is good to write reusable code.
Is possible to share the same Fragment class for both?
I’m thinking about a starting activity that “forks” the app in pre-honeycomb activities and post-honeycomb, reusing the same Fragment classes. The fact is if I include android.app.Fragment, the fragment will not be usable from a FragmentActivity and viceversa.
I could use only FragmentActivities, but this would prevent the use of the actionbar.
How to do this?
The solution in the example here does not seem to be appropriate.
For contacts the problem is that there is a class that is deprecated but you can still compile it.
With fragment if you refer to android.app.Fragment you can’t compile that class with the sdk < 3.0 while if use import android.support.v4.app.Fragment you can’t compile for honeycomb (you can only if you keep using the support lib even on honeycomb that does not seem to be the best thing to do).
I managed to do it only by having two different projects that expose two different implementations of a proxy. Than I use the right implementation for each sdk. It is not as simple as it looks because you will have to make a proxy for FragmentTransaction, FragmentManager etc.
It worked for me but it did not work for settings with fragment. In that case the xml files that use fragment can’t be compiled with pre honeycomb sdk.