if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONUT) { overridePendingTransition(R.anim.push_up_in,R.anim.push_up_out); }
但是这种写法在项目中使用的话,会出现问题,在1.6的测试机器上会出现一个VerifyError的错误,因为overridePendingTransition 会在加载类加载时调用,在1.6的机器上会进行一个预编译,直接这样写就会出现错误。
在国外某论坛搜索了一下,发现了这样一段话:
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.
这里已经很明确的给出了解决办法。
处理方式:
public class AnimationModel { private Activity context; public AnimationModel(Activity context){ this.context = context; } /** * call overridePendingTransition() on the supplied Activity. * @param a * @param b */ public void overridePendingTransition(int a, int b){ context.overridePendingTransition(a, b); } }
调用方式:
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONU) { (new AnimationModel(Profile.this)) .overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out); }
这样,你引用跳转动画函数的模型类是生成了,但是里边的函数是不会被调用的。这样就不会被加载到jvm中去。问题也就解决了。