Cocos2d-x 接入sdk遇到的小问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_31803737/article/details/52043237

Cocos2d-x 接入sdk遇到的小问题

第一次报错:调用sdk的函数的时候,异常,Can’t create handler inside thread that has not caller Looper.prepare();

第一次报错

解决方案: 在调用之前加入Looper.prepare();

第二次报错: 再次调用sdk的函数的时候,又异常了,Only one Looper may be created per thread

第二次报错

报错原因: 看了一点Looper的源码,知道了因为Looper.prepare();的时候就重新new了一个Looper,但一个Thread里只能有一个Looper。

解决方案: 在Looper.prepare();之前用if(Looper.myLooper() ==null)来判断是否当前Thread里已存在Looper,如果存在则直接调用sdk的函数。

注意: 不知道是不是正确的解决方案,但运行起来没有问题。有遇到同样问题的可以参考下。 **

猜你喜欢

转载自blog.csdn.net/sinat_31803737/article/details/52043237