I don’t know why this happen, or if it only happen with Android Studio, or with android targets.
I have this piece of code
var userData = null;
var userDataKey = USER_FILE;
var ls = cc.sys.localStorage;
userData = ls.getItem(userDataKey);
if (userData == null)
{
cc.log("No saved file... Saving new one");
SaveData();
}
else
{
var levelData = JSON.parse(userData);
LevelInfo = {};
LevelInfo = null;
LevelInfo = levelData;
}
The SaveData():
var SaveData = function()
{
var ls = cc.sys.localStorage;
var userDataKey = USER_FILE;
var userDataValue = JSON.stringify(LevelInfo);
ls.setItem(userDataKey, userDataValue);
};
Those codes are working on web and iOS… and they also work with Android, BUT, and here is my surprise, it doesn’t work at the beginning. When I press “Run” in Android Studio the game won’t start, showing a black screen; then if I comment the first block and I press “Run” again, the game works… and if I uncomment the code… it keeps working,
Why is this happening. Does someone had the same issues with cc.sys.localStorage. I’m using cocos2d-js 3.7.1. Also, I keep getting the warning “rejecting org/lib/localStorage”. But it works if I keep commenting/uncommenting that piece of code. What other way can I use to saves a js object?.