I’ve got an application that uses overridePendingTransition to do some custom animations upon transitioning from one activity to the other. This was made available in Android 2.0, but I want to make the application work on Android 1.6. I figured if I just checked that android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONUT, and if not, don’t do the overridePendingTransition.
However, I get a VerifyError, which I assume is caused by this:
VFY: Unable to resolve virtual method 346: ../../Login: overridePendingTransition (II)V
Is it not possible to use newer functionality conditionally based on the SDK version?
Yes, it is.
I am going to guess that your code looks like this:
If I am correct, then that will not work. The VM will attempt to find
overridePendingTransition()when the class is loaded, not when thatif()statement is executed.Instead, you should be able to do this:
where the implementation of
overridePendingTransition()inSomeClassDedicatedToThisOperationjust callsoverridePendingTransition()on the suppliedActivity.So long as
SomeClassDedicatedToThisOperationis not used anywhere else, its class will not be loaded until you are inside yourif()test, and you will not get theVerifyError.