VerifyError, or using overridePendingTransition while maintaining compatibility?
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: overridePendin开发者_JAVA百科gTransition (II)V
Is it not possible to use newer functionality conditionally based on the SDK version?
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 (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONUT) {
overridePendingTransition(...);
}
If I am correct, then that will not work. The VM will attempt to find overridePendingTransition()
when the class is loaded, not when that if()
statement is executed.
Instead, you should be able to do this:
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONUT) {
SomeClassDedicatedToThisOperation.overridePendingTransition(this, ...);
}
where the implementation of overridePendingTransition()
in SomeClassDedicatedToThisOperation
just calls overridePendingTransition()
on the supplied Activity
.
So long as SomeClassDedicatedToThisOperation
is not used anywhere else, its class will not be loaded until you are inside your if()
test, and you will not get the VerifyError
.
精彩评论