Crash when use unity as a android library

Unity version:2021.3.7f1c1
I use unity as a android library. I create a TextureView to display unity screen as follow:

public class UnityView extends TextureView implements TextureView.SurfaceTextureListener {
 
........
 
    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
      unityPlayer.displayChanged(0,  new Surface(surfaceTexture));
    }
 
    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int width, int height) {
      unityPlayer.displayChanged(0,  new Surface(surfaceTexture));
    }
 
    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) { 
      unityPlayer.displayChanged(0, null);
      return true;
    }
......
}

when app new and delete UnityView quickly, i got a crash.

2022-11-22 10:28:07.334 25967-25967/io.agora.WyMetaRTE E/CrashReport: java.lang.Error: FATAL EXCEPTION [main]

Unity version : 2021.3.7f1c1

Device model : Xiaomi Redmi 8

Device fingerprint: Xiaomi/olive/olive:9/PKQ1.190319.001/V11.0.11.0.PCNCNXM:user/release-keys

Build Type : Release

Scripting Backend : IL2CPP

ABI : arm64-v8a

Strip Engine Code : true

Caused by: 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:5038)

at android.view.ViewGroup.addView(ViewGroup.java:4869)

at android.view.ViewGroup.addView(ViewGroup.java:4809)

at android.view.ViewGroup.addView(ViewGroup.java:4782)

at com.unity3d.player.UnityPlayer$2.run(Unknown Source:24)

at android.os.Handler.handleCallback(Handler.java:873)

at android.os.Handler.dispatchMessage(Handler.java:99)

at android.os.Looper.loop(Looper.java:201)

at android.app.ActivityThread.main(ActivityThread.java:6861)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

2022-11-22 10:28:07.334 25967-25967/io.agora.WyMetaRTE E/CrashReport: #++++++++++++++++++++++++++++++++++++++++++#

content already has a View,use removeView ,then add a new

when ID=0,displaychanged methold is:

    public boolean displayChanged(int var1, Surface var2) {
        if (var1 == 0) {
            this.mMainDisplayOverride = var2 != null;
            this.runOnUiThread(new Runnable() {
                public final void run() {
                    if (UnityPlayer.this.mMainDisplayOverride) {
                        UnityPlayer.this.removeView(UnityPlayer.this.mGlView);
                    } else {
                        UnityPlayer.this.addView(UnityPlayer.this.mGlView);
                    }
                }
            });
        }

        return this.updateDisplayInternal(var1, var2);
    }