Skip to content
This repository has been archived by the owner on Jun 22, 2022. It is now read-only.

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. #56

Closed
tahaelsherif opened this issue Apr 24, 2020 · 9 comments

Comments

@tahaelsherif
Copy link

App crash when change language inside fragment

@akexorcist
Copy link
Owner

akexorcist commented Apr 26, 2020

@tahaelsherif It's look like you already added the view in parent and that code called again after configuration changes. Please supporting the configuration changes in your app to solve this.

If my answer is not related to your issue. Please provide more information about that view.

@tahaelsherif
Copy link
Author

tahaelsherif commented Apr 26, 2020

How do I support the configuration changes in my app ?
I'm using both of databinding and mvvm btw.

@akexorcist
Copy link
Owner

akexorcist commented Apr 27, 2020

Please see https://developer.android.com/guide/topics/resources/runtime-changes

This also happen when screen size changed (rotate device). To make sure that problem is about configuration changes, not the library. Please try to open that activity and rotate the device (without android:configChanges attribute in Activity).

@tahaelsherif
Copy link
Author

All activities are portrait only :)

@akexorcist
Copy link
Owner

@tahaelsherif Does not about your app support landscape or not. Just only enable screen orientation for test about your issue. There's many situation for config changes but screen orientation is easy to test.

@tahaelsherif
Copy link
Author

Ok i will try to test as many usecases as i can and i will let you know.

@tahaelsherif
Copy link
Author

tahaelsherif commented Apr 29, 2020

So finally it was not from your library the issue is caused by fragment inflating, the fragment was attached to the parent view.

This is the old one
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_buy_sell_list, container, true)

And then I changed it to this one
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_buy_sell_list, container, false)

And then everything was fixed anyway thank you for your time maybe you should mention this as a tip for your documentation.

@akexorcist
Copy link
Owner

@tahaelsherif I thought that inflate(..., ..., container, false) is the normal one. Why do you use true? (Curious only)

@tahaelsherif
Copy link
Author

Yes it's supposed to be false by default but I changed it to true once for some testing and i forgot to returing it to false before i added your librray , so i didn't know that this was cuasing the problem

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants