VerifyError, or using overridePendingTransition while maintaining compatibility?
Asked Answered
T

1

7

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?

Therapy answered 26/8, 2010 at 11:38 Comment(0)
C
15

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.

Centipede answered 26/8, 2010 at 12:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.