views:

143

answers:

1

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?

+4  A: 

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.

CommonsWare