Does the v4 support library support new classes when they are available?

I know that the v4 support library can be used to implement things in older versions of Android that were introduced in later versions, such as fragments. If we implement an application that uses the v4 support library to display fragments of the dialog, for example, does it use the latest code (i.e. the source and new fragments) when it runs on ICS, or does it still use the support code for each version of Android ?

Is there a way to use the android.app.Fragment and android.support.v4.app.Fragment classes in one application that are different at run time if we run the Android version with Fragment support, or do we need to use only support classes when importing the v4 support library?

Maybe I'm wrong, but it does not seem to me a good idea not to use the latest code when working on the latest platforms.

Adhering to the case of a fragment of dialogue, what do you think is better:

1) use the v4 support library, i.e. use compatibility code for all versions of Android

2) use the new android.app.DialogFragment when working at API level 11 or higher and use the deprecated methods showDialog and onCreateDialog of the Activity class when working at API level <; eleven

As I said, the best IMHO would be the following, but (correct me if I am wrong) this is not a possible solution:

3) use the new class android.app.DialogFragment when working at API level 11 or higher and use the class android.support.v4.app.DialogFragment when starting at API level <11

I apologize if I am a little embarrassed, I hope that the question is completely clear.

+8
android android-fragments android-dialogfragment android-support-library
source share
3 answers

When you use the support for android support in your project, even if the device has a compatible level of the Android API, so it does not need to use the compatibility library, it will still use the methods from the compatibility library.

EDIT

Looking through the Android v4 support library, she states (in the comments in the android.support.v4.app.Fragment class):

The support version of the static library framework android.app.Fragment. Used to record applications that run on platforms earlier to Android 3.0. When running on Android 3.0 or higher, the implementation is still used; he is not trying to switch to. See the SDK Infrastructure Documentation for Class Overview.

Link here .

+11
source share

If we implement an application that uses the v4 support library to display fragments of the dialog, for example, does it use the latest code (i.e. the source and new fragments) when it runs on ICS, or does it still use the support code for each version for Android?

For fragments, in particular, it always uses its own backport. In other cases, it may go to the original implementation, if any.

Is there a way to use both the android.app.Fragment class and the android.support.v4.app.Fragment class in the same application, which is different at runtime if we are working on the Android version of android or we need to use only support classes when importing v4 support libraries?

I would stick with support classes. You would add a ton of extra work without any real benefit by moving on to an alternative approach.

Maybe I'm wrong, but it does not seem to me a good idea not to use the latest code when working on the latest platforms.

Welcome to your opinion. For larger subsystems, such as fragments, the benefits will be outweighed due to the cost of IMHO.

Adhering to the case of a fragment of dialogue, what do you think is better:

The best option is not to use DialogFragment at all, instead find a way to accomplish what you want without using dialogs.

Of the three options you have presented, use option # 1. As soon as you feel that you can refuse to support Android 2.x, you can switch to using your own fragments throughout the application.

+6
source share

The program level API can be seen with this:

 int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= android.os.Build.VERSION_CODES.FROYO){ // Do something for froyo and above versions } else{ // do something for phones running an SDK before froyo } 

You can then duplicate your code to use the class you want by writing the fully qualified class name in your code, i.e. android.app.DialogFragment or android.support.v4.app.Fragment, not just DialogFragment.

+2
source share

All Articles