View Flipper Throws Exception in ViewFlipper.onDetachedFromWindow

I have a ViewFlipper in my Activity that is used as a ListView footer. I recently posted a post about a problem that I saw in the emulator. See Activity leaked to IntentReceiver android.widget.ViewFlipper . I found the answer to this question.

Now I see problems when debugging on the device. In fact, when a device configuration change (rotation) destroys my activity, I get a crash. See Journal.

 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 connected, this problem does not occur so often. It hurts me.

From what I see, ViewFlipper::onDetachedFromWindow trying to unregister a recipient that is not registered. This ViewFlipper was removed from the ListView using removeFooterView before calling ViewFlipper::onDetachedFromWindow .

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

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

Is there any other way to get the idea to be destroyed. I tried WindowManager.removeView , but this throws an exception saying the view has not been registered with WindowManager .

Any help is appreciated.

+1
source share
2 answers

I have the same problem as I had several times. I found this solution http://daniel-codes.blogspot.com/2010/05/viewflipper-receiver-not-registered.html , but I did not understand how to use it. So, I get the answer from here ViewFlipper: the receiver is not registered , and my problem is solved. Give it a try! I am sure this solution will help you.

+5
source

In my case, this plays on the screen when viewFlipper starts the animation. For some reason, the onDetachedFromWindow() method is not called for such a viewFlipper .

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

Alternatively, you can extend the viewFlipper class and override the onSaveInstanceState() method by adding a clearAnimation() call to it.

+1
source

Source: https://habr.com/ru/post/904902/


All Articles