Crash when Embedded to Android as a library

When I embedded cocos creator to an android project as a library. I separate cocos’s lifecycle method to two custom function ‘load’ and ‘unload’. It’s work fine like activity enter and exit in an activity. I can control the cocos init and destroy with my ‘load’ and ‘unload’.That’s good.
The issue is when several websocket object created from game. I unload(mean destroy) cocos. The websocket call back ‘onClosed’(in java) called after that. This callback will call cocos code to get an application(is destroyed now) cause crash.
I handle this problem to make sure all websocket close before destroy cocos(or activity exit).

Which version are you using ? And how did you publish it as a library

我们使用cocos 3.7.2,我们将GameActivity.java 和 CocosActivity.java的代码提取到我们自定义的一个activity中,提取其中的 cocos的生命周期,包括onCreate/onStart等等到一个自定义个函数中,实现自定义的控制cocos启动和卸载
我们发现问题:
在引擎卸载销毁之后,会有cocos全局静态的线程池依然在跑,导致崩溃(因为cocos实例已经不存在了)

刚刚测试并解决了activity无法回收的问题,当cocos作为一个库使用,在调用CocosHelper.init或者GlobalObject…设置activity未静态全局变量时,activity销毁,这些静态变量也需要置空,否则会导致activity.onDestory之后activity没有对象没有销毁导致内存泄漏

感谢同步结果

卸载cocos时,需要保证 websocket连接先断开,否则CocosWebSocket.onClosed有可能在卸载后被回调,此时native指向的cocos已经销毁导致崩溃,类似的情况还有资源加载,音效播放
GameInputProxy::handleAppCommand的代码片段
if (_eventCallback) {
// _eventCallback(cmd); // 某些机型100%崩溃
AndroidPlatform::eventCallback(cmd); // 自定义方法复现_eventCallback,用于解决崩溃
}

void UrlAudioPlayer::destroy() {
if (!*_isDestroyed) {
*_isDestroyed = true;
ALOGV(“UrlAudioPlayer::destroy() %p”, this);
SL_DESTROY_OBJ(_playObj); // 此处可能导致崩溃在我暂时无法解决,但是让游戏运行一段时间后才调用卸载看起来能减少发生的概率,这里的问题似乎在cocos2d-x时代就有了
ALOGV(“UrlAudioPlayer::destroy end”);
}
}
在1000次加载卸载后,内存顶峰从350+m飙升到400+m,看起来是有内存泄漏的

大佬们有计划解决作为 library 的崩溃问题吗