关于Cocos Creator构建的android程序第一次安装home键挂起再进入程序崩溃问题的解决方案

你或许会看到很多行这样的log

...
Cocos js error:(3822): <no filename=“filename”> line:0 msg:too much recursion
Cocos js error:(3822): <no filename=“filename”> line:0 msg:too much recursion
Cocos js error:(3822): <no filename=“filename”> line:0 msg:too much recursion
...

你在心中大骂Creator垃圾

其实这是个android系统的bug。。。

有很多android应用(没有对这个问题处理过的)第一次安装进入程序也会有这个问题

下面给出解决方案:

打开你的android-studio工程,在Cocos2dxActivety里的onCreate方法里的super.onCreate(saveInstanceState);的下面加上如下代码:

if(!this.isTaskRoot()) { 
    Intent mainIntent=getIntent();
    String action=mainIntent.getAction();
    if(mainIntent.hasCategory(Intent.CATEGORY_LAUNCHER) && action.equals(Intent.ACTION_MAIN)) {
        finish();
        return;
     }
}

参考下图

这里写图片描述


如果你也报了很多

Cocos js error:(3822): <no filename=“filename”> line:0

的错误,但又不是这个问题,我猜你很有可能是微信登录分享那里出了问题,你是不是没有在gl 线程里执行Cocos2dxJavascriptJavaBridge的回调方法?

Cocos2dxGLSurfaceView.getInstance().queueEvent(new Runnable() {
    @Override
    public void run() {
        Cocos2dxJavascriptJavaBridge.evalString("cc.log(\"potato47\")");
    }                                
});

猜你喜欢

转载自blog.csdn.net/potato47/article/details/70169481