我的ViewFlipper
中有一个Activity
,用作ListView
的页脚视图。关于我在模拟器中看到的问题,我已经发布了一段时间。见Activity has leaked IntentReceiver android.widget.ViewFlipper。我找到了答案。
现在,我在设备上调试时遇到问题。基本上当设备配置更改(旋转)导致我的活动被破坏时,我会崩溃。见日志。
01-19 14:56:19.679: E/AndroidRuntime(30240): FATAL EXCEPTION: main
01-19 14:56:19.679: E/AndroidRuntime(30240): java.lang.IllegalArgumentException: Receiver not registered: android.widget.ViewFlipper$1@4076f0c0
01-19 14:56:19.679: E/AndroidRuntime(30240): at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:610)
01-19 14:56:19.679: E/AndroidRuntime(30240): at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:840)
01-19 14:56:19.679: E/AndroidRuntime(30240): at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:331)
01-19 14:56:19.679: E/AndroidRuntime(30240): at android.widget.ViewFlipper.onDetachedFromWindow(ViewFlipper.java:104)
01-19 14:56:19.679: E/AndroidRuntime(30240): at android.view.View.dispatchDetachedFromWindow(View.java:6173)
01-19 14:56:19.679: E/AndroidRuntime(30240): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1164)
01-19 14:56:19.679: E/AndroidRuntime(30240): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1162)
01-19 14:56:19.679: E/AndroidRuntime(30240): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1162)
01-19 14:56:19.679: E/AndroidRuntime(30240): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1162)
01-19 14:56:19.679: E/AndroidRuntime(30240): at android.view.ViewRoot.dispatchDetachedFromWindow(ViewRoot.java:1748)
01-19 14:56:19.679: E/AndroidRuntime(30240): at android.view.ViewRoot.doDie(ViewRoot.java:2759)
01-19 14:56:19.679: E/AndroidRuntime(30240): at android.view.ViewRoot.die(ViewRoot.java:2729)
01-19 14:56:19.679: E/AndroidRuntime(30240): at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:218)
01-19 14:56:19.679: E/AndroidRuntime(30240): at android.view.Window$LocalWindowManager.removeViewImmediate(Window.java:436)
01-19 14:56:19.679: E/AndroidRuntime(30240): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:2705)
有趣的是,如果未附加调试器,则此问题不会经常发生。这让我很沮丧。
从我所看到的ViewFlipper::onDetachedFromWindow
试图取消注册未注册的接收者。在ViewFlipper
被调用之前,ListView
已使用removeFooterView
从ViewFlipper::onDetachedFromWindow
中移除。
这是我用来从列表视图中删除viewFlipper的方法:
mLoadMoreFlipper.stopFlipping();
mLoadMoreFlipper.removeAllViews();
getExpandableListView().removeFooterView(mLoadMoreFlipper);
mLoadMoreFlipper = null;
还有其他方法强制销毁视图。我已经尝试了WindowManager.removeView
但是会抛出一个例外the view has not been registered with WindowManager
。
感谢任何帮助。
答案 0 :(得分:5)
我和前几天有同样的问题。我找到了这个解决方案http://daniel-codes.blogspot.com/2010/05/viewflipper-receiver-not-registered.html,但我不明白如何使用它。所以,我从这里得到答案ViewFlipper : Receiver not registered,我的问题已经解决了。试试吧!我相信这个解决方案会对你有帮助。
答案 1 :(得分:1)
在我的情况下,当viewFlipper
运行动画时,在屏幕上重现此旋转。由于某些原因,onDetachedFromWindow()
方法未在此viewFlipper
上调用。
我已在m_viewFlipper.clearAnimation()
方法中调用MyActivity.onPause()
来解决此问题。
或者,可以扩展ViewFlipper
类并覆盖onSaveInstanceState()
方法,添加clearAnimation()
次调用。