我有一个窗口弹出类,它在AOS 2.x(如2.2.2、2.3.5等)中运行良好,但在AOS 4.x中崩溃。导致崩溃的代码如下:

public void dismissPopup(){
    if (!isVisible)
        return;
    isVisible = false;

    final Animation animation = AnimationUtils.loadAnimation(activity, R.anim.popup_hide);
    animation.setAnimationListener(new AnimationListener() {
        public void onAnimationEnd(final Animation animation) {
            // The animation has ended
            popupWindow.dismiss();
        }
        public void onAnimationRepeat(final Animation animation) {}
        public void onAnimationStart(final Animation animation) {}
    });
    popupView.startAnimation(animation);
}

所以要使它在aos 4.x中工作,我必须注释所有动画行,就像它有2b:
public void dismissPopup(){
    if (!isVisible)
        return;
    isVisible = false;

    popupWindow.dismiss();
}

这在AOS 4.1.x中运行良好,但不提供动画。有什么问题吗?android不应该提供向后兼容吗?
事故日志
04-25 21:05:50.387: E/AndroidRuntime(8997): FATAL EXCEPTION: main
04-25 21:05:50.387: E/AndroidRuntime(8997): java.lang.NullPointerException
04-25 21:05:50.387: E/AndroidRuntime(8997):     at android.view.ViewRootImpl.drawAccessibilityFocusedDrawableIfNeeded(ViewRootImpl.java:2301)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at android.view.ViewRootImpl.onHardwarePostDraw(ViewRootImpl.java:1931)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1182)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at android.view.ViewRootImpl.draw(ViewRootImpl.java:2147)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2019)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1830)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:736)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at android.view.Choreographer.doCallbacks(Choreographer.java:566)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at android.view.Choreographer.doFrame(Choreographer.java:536)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:722)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at android.os.Handler.handleCallback(Handler.java:615)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at android.os.Looper.loop(Looper.java:137)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at android.app.ActivityThread.main(ActivityThread.java:4745)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at java.lang.reflect.Method.invokeNative(Native Method)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at java.lang.reflect.Method.invoke(Method.java:511)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-25 21:05:50.387: E/AndroidRuntime(8997):     at dalvik.system.NativeStart.main(Native Method)

upd:动画在aos 4.0.3中工作,但在4.1.1中崩溃

最佳答案

我找到了一个愚蠢但可行的办法:

animation.setAnimationListener(new AnimationListener() {
    public void onAnimationEnd(final Animation animation) {
        // The animation has ended
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                popupWindow.dismiss();
            }
        });
    }
    public void onAnimationRepeat(final Animation animation) {}
    public void onAnimationStart(final Animation animation) {}
});

我甚至无法想象为什么在4.1.1中没有这个功能和为什么它不能工作…

10-08 17:06