1

I have a ViewFlipper in my Activity that is used as a footer view of a ListView. I had posted a while back regarding an issue I was seeing in the emulator. See Activity has leaked IntentReceiver android.widget.ViewFlipper. I found an answer to that yet.

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.

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)

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

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

This is what I use to remove the viewFlipper from the list view:

mLoadMoreFlipper.stopFlipping();
mLoadMoreFlipper.removeAllViews();
getExpandableListView().removeFooterView(mLoadMoreFlipper);
mLoadMoreFlipper = null;

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

Any help is appreciated.

Community
  • 1
  • 1
Code Poet
  • 11,227
  • 19
  • 64
  • 97
  • 1
    I have this problem too. Look the solution I got : http://stackoverflow.com/questions/8050730/viewflipper-receiver-not-registered – Gabrielle Jan 19 '12 at 09:55
  • This doesn't seem to work for me. I'm still getting the exceptions. Oddly my `onDetachedFromWindow` override is never called. – Code Poet Jan 19 '12 at 12:25
  • Got a handle on the `onDetachFromWindow` problem at least. Testing now. – Code Poet Jan 19 '12 at 18:02
  • Seems to fix the problem. Thank you so much. Please enter this as an answer and I will reward you the points. – Code Poet Jan 20 '12 at 06:18

2 Answers2

5

I have the same problem as I had few time ago. I found this solution http://daniel-codes.blogspot.com/2010/05/viewflipper-receiver-not-registered.html but I didn't understand how to use it. So, I get the answer from here ViewFlipper : Receiver not registered and my problem has been solved. Try it! I'm sure this solution will help you.

Community
  • 1
  • 1
Gabrielle
  • 4,933
  • 13
  • 62
  • 122
1

In my case this reproduced on screen rotate when viewFlipper runs animation. By some reason onDetachedFromWindow() method is not called on such viewFlipper.

I have fixed this by calling m_viewFlipper.clearAnimation() in MyActivity.onPause() method.

Alternatively one can extend ViewFlipper class and override onSaveInstanceState() method adding there clearAnimation() call.

Dmitry
  • 31
  • 2