View Flipper Throws Exception in ViewFlipper.onDetachedFromWindow
<p>I have a <code>ViewFlipper</code> in my <code>Activity</code> that is used as a footer view of a <code>ListView</code>. I had posted a while back regarding an issue I was seeing in the emulator. See <a href="http://stackoverflow.com/questions/8701042/activity-has-leaked-intentreceiver-android-widget-viewflipper">Activity has leaked IntentReceiver android.widget.ViewFlipper</a>. I found an answer to that yet.</p>

<p>Now, I'm seeing problems when debugging on a device. Essentially when device configuration change (rotation) causes my activity to be destroyed, I get a crash. See log. </p>

<pre><code>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)
</code></pre>

<p>Interestingly if the debugger is not attached this problem does not occur as often. This is crippling me. </p>

<p>From what I can see <code>ViewFlipper::onDetachedFromWindow</code> is trying to unregister a receiver which is not registered. This <code>ViewFlipper</code> has been removed from the <code>ListView</code> using <code>removeFooterView</code> before <code>ViewFlipper::onDetachedFromWindow</code> is called.</p>

<p>This is what I use to remove the viewFlipper from the list view:</p>

<pre><code>mLoadMoreFlipper.stopFlipping();
mLoadMoreFlipper.removeAllViews();
getExpandableListView().removeFooterView(mLoadMoreFlipper);
mLoadMoreFlipper = null;
</code></pre>

<p>Is there any other way to force destroy a view. I've tried <code>WindowManager.removeView</code> but that throws an exception saying <code>the view has not been registered with WindowManager</code>. </p>

<p>Any help is appreciated.</p>
