akexorcist / Localization

[Android] In-app language changing library
Apache License 2.0
983 stars 154 forks source link

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

Closed tahaelsherif closed 4 years ago

tahaelsherif commented 4 years ago

App crash when change language inside fragment

akexorcist commented 4 years ago

@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 commented 4 years ago

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

akexorcist commented 4 years ago

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 commented 4 years ago

All activities are portrait only :)

akexorcist commented 4 years ago

@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 commented 4 years ago

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

tahaelsherif commented 4 years ago

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 commented 4 years ago

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

tahaelsherif commented 4 years ago

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