AOS 4.x crash issue with animation

2019-07-16 12:11发布

I have a window popup class which works fine in aos 2.x (like 2.2.2, 2.3.5 etc) but crashes in aos 4.x. Code which causes crash is the following:

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);
}

so to make it work in aos 4.x I have to comment all the animation lines, like it has 2b:

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

    popupWindow.dismiss();
}

this works fine in aos 4.1.x but provides no animation. What could be the issue here? Shouldn't android provide any BACKWARD compatibility?
the crash log

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: animation works in aos 4.0.3 but crashes in 4.1.1

1条回答
Animai°情兽
2楼-- · 2019-07-16 12:33

Its stupid but workaround I found is:

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) {}
});

I can't even imagine why this helps and why it doesn't work without it in 4.1.1...

查看更多
登录 后发表回答