2013-04-25 159 views
1

我有一個窗口彈出類,它在aos 2.x(如2.2.2,2.3.5等)中正常工作,但在aos 4.x中崩潰。這會導致崩潰的代碼如下:動畫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,但沒有提供動畫。這裏可能是什麼問題?不應該提供任何後退兼容性?
崩潰日誌

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

+0

堆棧溢出俱樂部的第一條規則:如果你的ap p崩潰,發佈你的logcat(並將人指向特定的行號)。 – 2013-04-25 17:47:43

+0

我沒有看到任何鏈接到我的代碼在崩潰日誌中,所以我忘了它... – Stan 2013-04-25 18:05:41

+0

難道是'R.anim.popup_hide'還沒有被你定義,但你寧願在那裏使用Android動畫?也許這在Android 4上消失了? – 2013-04-25 18:09:43

回答

2

其愚蠢的,但解決辦法,我發現是:

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中工作......

+0

你節省了我的一天。在對旋轉器項目應用動畫時面臨相同的問題。非常感謝解決方案。 – Smeet 2015-02-23 10:36:11