uCrop icon indicating copy to clipboard operation
uCrop copied to clipboard

IllegalStateException occurs when returning to UCropFragment

Open KiYoEcol opened this issue 3 years ago • 2 comments

Do you want to request a feature or report a bug? bug

What is the current behavior? IllegalStateException occurs and the app is crash. Because UCropFrgment add again the already instantiated mBlookingView to RelativeLayout, this exception occurs.

What is the expected behavior? No crash

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. You move from UCropFragment to the next Fragment. When you return to UCropFragment from the next Fragment by using the back button, IllegalStateException occurs.

Please attach any image files, URL and stack trace that can be used to reproduce the bug.

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
        at android.view.ViewGroup.addViewInner(ViewGroup.java:5099)
        at android.view.ViewGroup.addView(ViewGroup.java:4930)
        at android.view.ViewGroup.addView(ViewGroup.java:4870)
        at android.view.ViewGroup.addView(ViewGroup.java:4843)
        at com.yalantis.ucrop.UCropFragment.addBlockingView(UCropFragment.java:542)
        at com.yalantis.ucrop.UCropFragment.onCreateView(UCropFragment.java:133)
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2699)
        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:320)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1199)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1368)
        at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1446)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1509)
        at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2637)
        at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2589)
        at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2723)
        at androidx.fragment.app.FragmentStateManager.activityCreated(FragmentStateManager.java:346)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1200)
        at androidx.fragment.app.FragmentManager.addAddedFragments(FragmentManager.java:2236)
        at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2009)
        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1965)
        at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1861)
        at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
        at android.os.Handler.handleCallback(Handler.java:907)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:216)
        at android.app.ActivityThread.main(ActivityThread.java:7625)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)

Which versions of uCrop, and which Android API versions are affected by this issue? Did this work in previous versions of uCrop? uCrop version: 2.2.6 Android API: 29

KiYoEcol avatar Feb 19 '21 04:02 KiYoEcol

I have the same issue:

Device: Galaxy S20 FE Android version: 12 UCrop version: 2.2.8

Did anyone manage to solve this issue or a find workaround?

aacic avatar May 23 '22 14:05 aacic

I have same issue too. Is there any work on this progress?

This happens when I

  • Using multiple uCropFragments and when I replace fragments with each other, previously initialized fragment is throwing this error. Because mBlockingView is not null and because it has already a parent. This shouldn't be add to parent view without checking it has a parent or not.

okarakose avatar May 25 '22 14:05 okarakose